![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Breaking out of FOREACH Is there a NEXT or CONTINUE or similar for the FOREACH loop? How about BREAK? Thanks. |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Breaking out of FOREACH On Wed, 20 Dec 2006 19:00:00 -0800, John Smith <JohnSmith@discussions.microsoft.com> wrote: > Is there a NEXT or CONTINUE or similar for the FOREACH loop? > > How about BREAK? Not that I know of. If you don't mind some complex and unreadable constructs, you can try to simulate them through creative use of IF. For example, to process the first five objects in the pipe (here it just passes them through) and skip the rest as if there had been a break after the fifth: foreach { if($done -eq 0) { $_; $n=$n+1; if($n -eq 5) {$done=1} } } -begin { $n=0; $done=0 } (that's all on one line) |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Breaking out of FOREACH see get-help about_break get-help about_continue -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty "Lucvdv" wrote: > On Wed, 20 Dec 2006 19:00:00 -0800, John Smith > <JohnSmith@discussions.microsoft.com> wrote: > > > Is there a NEXT or CONTINUE or similar for the FOREACH loop? > > > > How about BREAK? > > Not that I know of. > > If you don't mind some complex and unreadable constructs, you can try to > simulate them through creative use of IF. > > > For example, to process the first five objects in the pipe (here it just > passes them through) and skip the rest as if there had been a break after > the fifth: > > foreach { if($done -eq 0) { $_; $n=$n+1; if($n -eq 5) {$done=1} } } -begin > { $n=0; $done=0 } > > (that's all on one line) > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Breaking out of FOREACH On Thu, 21 Dec 2006 06:46:02 -0800, RichS <RichS@discussions.microsoft.com> wrote: > see > > get-help about_break > get-help about_continue <rant> For as long as I've been using MS software (and that's since long before they bought QDOS from Tim Patterson and renamed it to MS-DOS), I've always wondered how people found out about these things. MS documentation is, and has always been decent-at-best as a reference, but utterly useless for learning. Break and continue are definitely NOT documented in the places where you'd expect them first, the Getting Started Guide and the PowerShell Primer. There's a chapter about FOREACH in the primer, but it doesn't mention break or continue. The word 'break' doesn't even occur in either of those two documents, AT ALL. The same with the online help for FOREACH: you would _at_the_very_least_ expect references in the "related links" section, but zippo. What you do find there is a number of other cmdlets that have far less to do with foreach-object, but that also happen to have 'object' as their noun. Typical. And to make it even worse, if you try by guessing because it simply 'has' to exist: C:\Temp\PowerShell> help break Get-Help : Cannot find Help for topic "break". </rant> |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Breaking out of FOREACH If you've not seen the about documentation before it would be worth doing somthing like get-help about* | select name, synopsis | format-list scroll down the list & see whats there and of course get-command will give you a list of all the cmdlets available -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty "Lucvdv" wrote: > On Thu, 21 Dec 2006 06:46:02 -0800, RichS <RichS@discussions.microsoft.com> > wrote: > > > see > > > > get-help about_break > > get-help about_continue > > <rant> > > For as long as I've been using MS software (and that's since long before > they bought QDOS from Tim Patterson and renamed it to MS-DOS), I've always > wondered how people found out about these things. MS documentation is, and > has always been decent-at-best as a reference, but utterly useless for > learning. > > > Break and continue are definitely NOT documented in the places where you'd > expect them first, the Getting Started Guide and the PowerShell Primer. > There's a chapter about FOREACH in the primer, but it doesn't mention break > or continue. The word 'break' doesn't even occur in either of those two > documents, AT ALL. > > The same with the online help for FOREACH: you would _at_the_very_least_ > expect references in the "related links" section, but zippo. What you do > find there is a number of other cmdlets that have far less to do with > foreach-object, but that also happen to have 'object' as their noun. > Typical. > > > And to make it even worse, if you try by guessing because it simply 'has' > to exist: > > C:\Temp\PowerShell> help break > Get-Help : Cannot find Help for topic "break". > > </rant> > |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: Breaking out of FOREACH Thanks. I found HELP ABOUT_CONTINUE after posting the query. I was careful about doing my due diligence before posting. I was searching for it under HELP ABOUT_FOREACH. Even piped the output to a file and scanned it with a word processor. I agree 100% with your rant. I would have written it myself. |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: Breaking out of FOREACH One would expect CONTINUE to be defined in HELP ABOUT_FOREACH and HELP ABOUT_FOR. Imagine ELSE is not mentioned in HELP ABOUT_IF but by itself under HELP ABOUT_ELSE. "RichS" wrote: > If you've not seen the about documentation before it would be worth doing > somthing like > > get-help about* | select name, synopsis | format-list > |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: Breaking out of FOREACH if you try by guessing because it simply 'has' >> to exist: the first thing I would have tought of, and how I find out :-) ls $PSHOME\en-US\*.txt | select-string 'Break' ah why did I not think about that feeling ? but serious, it would not be needed !, but still I do this a lot (where did I find that info again ?). Greetings /\/\o\/\/ "RichS" <RichS@discussions.microsoft.com> wrote in message news:AE02045D-843E-42EF-9599-0991089D52E6@microsoft.com... > If you've not seen the about documentation before it would be worth doing > somthing like > > get-help about* | select name, synopsis | format-list > > scroll down the list & see whats there > > and of course > > get-command > > will give you a list of all the cmdlets available > -- > Richard Siddaway > > Please note that all scripts are supplied "as is" and with no warranty > > > "Lucvdv" wrote: > >> On Thu, 21 Dec 2006 06:46:02 -0800, RichS >> <RichS@discussions.microsoft.com> >> wrote: >> >> > see >> > >> > get-help about_break >> > get-help about_continue >> >> <rant> >> >> For as long as I've been using MS software (and that's since long before >> they bought QDOS from Tim Patterson and renamed it to MS-DOS), I've >> always >> wondered how people found out about these things. MS documentation is, >> and >> has always been decent-at-best as a reference, but utterly useless for >> learning. >> >> >> Break and continue are definitely NOT documented in the places where >> you'd >> expect them first, the Getting Started Guide and the PowerShell Primer. >> There's a chapter about FOREACH in the primer, but it doesn't mention >> break >> or continue. The word 'break' doesn't even occur in either of those two >> documents, AT ALL. >> >> The same with the online help for FOREACH: you would _at_the_very_least_ >> expect references in the "related links" section, but zippo. What you do >> find there is a number of other cmdlets that have far less to do with >> foreach-object, but that also happen to have 'object' as their noun. >> Typical. >> >> >> And to make it even worse, if you try by guessing because it simply 'has' >> to exist: >> >> C:\Temp\PowerShell> help break >> Get-Help : Cannot find Help for topic "break". >> >> </rant> >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| LM Breaking Attachments | Scott | Live Mail | 5 | 04-29-2008 08:39 PM |
| OT - Breaking News | Mac | Vista General | 19 | 07-03-2007 02:52 PM |
| foreach, foreach-object & begin/process/end scriptblock clauses... | Clint Bergman | PowerShell | 12 | 05-16-2007 05:30 PM |
| Difference in semantics of for, foreach and foreach-object | Andrew Watt [MVP] | PowerShell | 3 | 01-26-2007 12:46 PM |
| possible bug with using the $foreach keyword inside foreach loops.. | klumsy@gmail.com | PowerShell | 6 | 11-16-2006 06:50 PM |