Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I branch in PowerShell? i.e. goto label?

6,521 views
Skip to first unread message

Bob

unread,
Jan 20, 2008, 9:59:21 AM1/20/08
to
How do I branch in PowerShell? i.e. goto label?

--
Thanks,
Bob

RichS

unread,
Jan 20, 2008, 10:42:01 AM1/20/08
to
PowerShell doesn't have a GOTO statement.

if you want to use GOTO to call a subroutine then use a PowerShell function

if you want to loop then use one of the looping constructions for, do, while
as appropriate

if you want to post your code showing how you are trying to use goto we can
give you the PowerShell equivalent
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

Hal Rottenberg

unread,
Jan 20, 2008, 11:17:10 AM1/20/08
to
Bob wrote:
> How do I branch in PowerShell? i.e. goto label?

You don't because PowerShell isn't designed to be used that way. I suggest you
read a little bit about different programming paradigms on Wikipedia, there's
some interesting stuff in there. The short version is that PowerShell is an
object-oriented language rather than procedural. Goto is an example of a
statement used in unstructured procedural programming. Some links:

http://en.wikipedia.org/wiki/Procedural_programming
http://en.wikipedia.org/wiki/Object_oriented_programming

If you are having trouble wrapping your head around the concept, let us know
what the problem you are trying to solve is and we can give you some concrete
examples.

For the record, I do NOT have a CS degree. :)

--

Hal Rottenberg
Blog: http://halr9000.com
Webmaster, Psi (http://psi-im.org)
Co-host, PowerScripting Podcast (http://powerscripting.net)

Karl Prosser[MVP]

unread,
Jan 22, 2008, 3:07:13 PM1/22/08
to
Powershell does have the ability to break to a label, which if used
carefully is powerful, especially for breaking out of nested loops. and
this is the scenario why C# also still has a goto statement.

RMSe17

unread,
Feb 19, 2008, 12:53:03 AM2/19/08
to
If it has no goto or equivalent instruction, then porting batch
scripts to powershell scripts becomes rather a pain. When I think of
a scripting language, I don't see why there would be no goto
command..
*sigh*

RMSe17

On Jan 22, 3:07 pm, "Karl Prosser[MVP]" <karl@p_o_w_e_r_s_h_e_l_l.com>
wrote:

Karl Prosser[MVP]

unread,
Feb 22, 2008, 2:12:33 PM2/22/08
to RMSe17
its not hard to change to doing things structurely. You'll find that
powershells language structure are rich and flexible - compared to those
of batch

goes perl, ruby and python have a goto?

Karl Prosser[MVP]

unread,
Feb 22, 2008, 2:15:14 PM2/22/08
to RMSe17
0 new messages