Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - BREAK out of a LOOP

Reply
 
Old 01-14-2008   #1 (permalink)
Sue & Bill


 
 

BREAK out of a LOOP

Is there a way to BREAK out of a LOOP? How about CONTINUE/NEXT?

Thanks.

My System SpecsSystem Spec
Old 01-14-2008   #2 (permalink)
IT Staff


 
 

Re: BREAK out of a LOOP

yes, BREAK is the command

"Sue & Bill" <sue.and.bill@xxxxxx> wrote in message
news:999087fa-536c-48a2-879c-d3edab5fe6de@xxxxxx
Quote:

> Is there a way to BREAK out of a LOOP? How about CONTINUE/NEXT?
>
> Thanks.

My System SpecsSystem Spec
Old 01-14-2008   #3 (permalink)
RichS


 
 

Re: BREAK out of a LOOP

see

get-help about_break

get-help about_continue

for details
--
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


"IT Staff" wrote:
Quote:

> yes, BREAK is the command
>
> "Sue & Bill" <sue.and.bill@xxxxxx> wrote in message
> news:999087fa-536c-48a2-879c-d3edab5fe6de@xxxxxx
Quote:

> > Is there a way to BREAK out of a LOOP? How about CONTINUE/NEXT?
> >
> > Thanks.
>
>
>
My System SpecsSystem Spec
Old 01-20-2008   #4 (permalink)
Anthony Houssa


 
 

Re: BREAK out of a LOOP

In their articles to prepare the 2008 Winter Scripting Games, "The Scripting
Guys" explain how to exit a loop in PowerShell (in Perl, and vbscript too).

The link:
http://www.microsoft.com/technet/scr...p0111.mspx#ERD
As mentioned in the article, PowerShell also enables to attach a label to a
loop

:OutsideLoop for ($y = 1; $y -le 5; $y++)
{
write-host "Loop number $y"
for ($i = 1; $i -le 3 ; $i++)
{
if ($y -eq 2) {break OutsideLoop}
$i
}
}

Regards

"RichS" <RichS@xxxxxx> wrote in message
news:5DB6AD7E-6E4A-4922-A08F-0E00058A6A45@xxxxxx
Quote:

> see
>
> get-help about_break
>
> get-help about_continue
>
> for details
> --
> 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
>
>
> "IT Staff" wrote:
>
Quote:

>> yes, BREAK is the command
>>
>> "Sue & Bill" <sue.and.bill@xxxxxx> wrote in message
>> news:999087fa-536c-48a2-879c-d3edab5fe6de@xxxxxx
Quote:

>> > Is there a way to BREAK out of a LOOP? How about CONTINUE/NEXT?
>> >
>> > Thanks.
>>
>>
>>
My System SpecsSystem Spec
Old 01-22-2008   #5 (permalink)
Karl Prosser[MVP]


 
 

Re: BREAK out of a LOOP

I recommend only using break inside a language contruct look like
foreach($a in $b) rather than in foreach-object

because if a break happens to escape outside of a language loop, it can
BReAK the whole pipeline as it stops the pipelines and causes the
cmdlets to get an exception.

-Karl

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to break an old raid Drivers
Break is not working ? PowerShell
Did I break it ? General Discussion
Break away Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46