![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Is there a 'continue' construct for loops in VBScript Hi, As you might have guessed, both from this post and the one I made yesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet, cannot find a construct such as 'continue' for loops. I'm assuming that many in this forum are familiar with languages like C or Java and will recognize this keyword. I need a way to start at the top of a For Each loop if a specific condition is met, but can't seem to find Continue. I shall keep looking while awaiting replies. Thanks for any help, Andy |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Is there a 'continue' construct for loops in VBScript Andrew Falanga wrote: Quote: > Hi, > > As you might have guessed, both from this post and the one I made > yesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet, > cannot find a construct such as 'continue' for loops. I'm assuming > that many in this forum are familiar with languages like C or Java and > will recognize this keyword. > > I need a way to start at the top of a For Each loop if a specific > condition is met, but can't seem to find Continue. I shall keep > looking while awaiting replies. > isn't needed. Typically an If statement is needed: for ... if ... then 'do something elseif ... then 'do something else else 'do nothing - essentially continuing the loop end if next Select Case can also be used. -- Microsoft MVP - ASP/ASP.NET - 2004-2007 Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM" |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Is there a 'continue' construct for loops in VBScript Does it have to be For/Next? In a For/Next loop you can use Exit For: For Each OFile in oFiles If oFile.Name = "SomethingOrOther.txt" then exit for '-- other ops here Next If you can use a Do loop then you have other options. There are While and Until keywords. (Look it up in the WSH CHM help file.) There's also Exit Do: Do While x = 0 '-- ops here. Loop Do If x = 0 then Exit Do '-- ops here. Loop Quote: > As you might have guessed, both from this post and the one I made > yesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet, > cannot find a construct such as 'continue' for loops. I'm assuming > that many in this forum are familiar with languages like C or Java and > will recognize this keyword. > > I need a way to start at the top of a For Each loop if a specific > condition is met, but can't seem to find Continue. I shall keep > looking while awaiting replies. > > Thanks for any help, > Andy |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Is there a 'continue' construct for loops in VBScript Andrew Falanga schrieb: Quote: > Hi, > > As you might have guessed, both from this post and the one I made > yesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet, > cannot find a construct such as 'continue' for loops. I'm assuming > that many in this forum are familiar with languages like C or Java and > will recognize this keyword. > > I need a way to start at the top of a For Each loop if a specific > condition is met, but can't seem to find Continue. I shall keep > looking while awaiting replies. > > Thanks for any help, > Andy the "continue" statement to special cases: #include <stdio.h> int main( void ) { int nIdx; for( nIdx = 0; nIdx <= 5; ++nIdx ) { printf( "%d is evil (as all numbers are)\n", nIdx ); if ( 2 != nIdx ) { continue; } printf( "but %d is especially mean and hates %d\n", nIdx, nIdx + 1 ); ++nIdx; } return 0; } output: evilnums.exe 0 is evil (as all numbers are) 1 is evil (as all numbers are) 2 is evil (as all numbers are) but 2 is especially mean and hates 3 4 is evil (as all numbers are) 5 is evil (as all numbers are) in VBScript you can use an If statement with reverted condition: Dim nIdx For nIdx = 0 To 5 WScript.Echo nIdx, "is evil (as all numbers are)" If 2 = nIdx Then WScript.Echo "but", nIdx, "is especially mean and hates", nIdx + 1 nIdx = nIdx + 1 End If Next output: === continueVBS: continue in VBScript 0 is evil (as all numbers are) 1 is evil (as all numbers are) 2 is evil (as all numbers are) but 2 is especially mean and hates 3 4 is evil (as all numbers are) 5 is evil (as all numbers are) === continueVBS: 0 done (00:00:00) === |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: Is there a 'continue' construct for loops in VBScript On Oct 9, 10:10*am, "ekkehard.horner" <ekkehard.hor...@xxxxxx> wrote: Quote: > Andrew Falanga schrieb: > Quote: > > Hi, Quote: > > As you might have guessed, both from this post and the one I made > > yesterday, I'm a VBScript neophyte. *I'm looking on MSDN but, as yet, > > cannot find a construct such as 'continue' for loops. *I'm assuming > > that many in this forum are familiar with languages like C or Java and > > will recognize this keyword. Quote: > > I need a way to start at the top of a For Each loop if a specific > > condition is met, but can't seem to find Continue. *I shall keep > > looking while awaiting replies. Quote: > > Thanks for any help, > > Andy > In C you can use "continue" in a loop to restrict the code following > the "continue" statement to special cases: > > * * *#include <stdio.h> > > * * *int main( void ) > * * *{ > * * * *int nIdx; > * * * *for( nIdx = 0; nIdx <= 5; ++nIdx ) > * * * *{ printf( "%d is evil (as all numbers are)\n", nIdx ); > * * * * *if ( 2 != nIdx ) > * * * * *{ continue; > * * * * *} > * * * * *printf( "but %d is especially mean and hates %d\n", nIdx, nIdx + 1 ); > * * * * *++nIdx; > * * * *} > * * * *return 0; > * * *} > > output: > > * * *evilnums.exe > * * *0 is evil (as all numbers are) > * * *1 is evil (as all numbers are) > * * *2 is evil (as all numbers are) > * * *but 2 is especially mean and hates 3 > * * *4 is evil (as all numbers are) > * * *5 is evil (as all numbers are) > > in VBScript you can use an If statement with reverted condition: > > * *Dim nIdx > * *For nIdx = 0 To 5 > * * * *WScript.Echo nIdx, "is evil (as all numbers are)" > * * * *If 2 = nIdx Then > * * * * * WScript.Echo "but", nIdx, "is especially mean and hates", nIdx + 1 > * * * * * nIdx = nIdx + 1 > * * * *End If > * *Next > > output: > > * *=== continueVBS: continue in VBScript > * *0 is evil (as all numbers are) > * *1 is evil (as all numbers are) > * *2 is evil (as all numbers are) > * *but 2 is especially mean and hates 3 > * *4 is evil (as all numbers are) > * *5 is evil (as all numbers are) > * *=== continueVBS: 0 done (00:00:00) === Andy |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: Is there a 'continue' construct for loops in VBScript Andrew Falanga wrote: Quote: > Hi, > > As you might have guessed, both from this post and the one I made > yesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet, > cannot find a construct such as 'continue' for loops. I'm assuming > that many in this forum are familiar with languages like C or Java and > will recognize this keyword. > > I need a way to start at the top of a For Each loop if a specific > condition is met, but can't seem to find Continue. I shall keep > looking while awaiting replies. Next statement. For Each ... If condition = True Then Exit For Next -- Todd Vargo (Post questions to group only. Remove "z" to email personal messages) |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: Is there a 'continue' construct for loops in VBScript "Todd Vargo" <tlvargo@xxxxxx> wrote in message news:edzFuNlKJHA.4600@xxxxxx Quote: > Andrew Falanga wrote: Quote: >> Hi, >> >> As you might have guessed, both from this post and the one I made >> yesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet, >> cannot find a construct such as 'continue' for loops. I'm assuming >> that many in this forum are familiar with languages like C or Java and >> will recognize this keyword. >> >> I need a way to start at the top of a For Each loop if a specific >> condition is met, but can't seem to find Continue. I shall keep >> looking while awaiting replies. > It sounds like either you want to Exit from the loop or are looking for > the > Next statement. > > For Each ... > If condition = True Then Exit For > Next the next one, not actually exit the loop entirely. I think that is what the "continue" construct does in those other languages he mentions. Bob Barrows had the best solution, however it reflects only one model. Here is the generic continue: for each ... do some stuff before deciding if A continue (i.e. start the next iteration of the loop now) do some more stuff next This maps to: for each ... do some stuff before deciding if not A then do some more stuff end if next It gets more complicated if the choice to continue is nested more deeply in some other loop of if block... I agree with Bob on the approach: don't try to map a continue'd structure in a language lacking continue... think the problem through a different way that uses only the available constructs. /Al |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: Is there a 'continue' construct for loops in VBScript "Andrew Falanga" <af300wsm@xxxxxx> wrote in message news:17cf1f2b-2394-44b6-a691-27c518813b43@xxxxxx Quote: > Hi, > > As you might have guessed, both from this post and the one I made > yesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet, > cannot find a construct such as 'continue' for loops. I'm assuming > that many in this forum are familiar with languages like C or Java and > will recognize this keyword. > > I need a way to start at the top of a For Each loop if a specific > condition is met, but can't seem to find Continue. I shall keep > looking while awaiting replies. > > Thanks for any help, > Andy For Each obj_TargetSubFolder in col_TargetSubFolders Do ' some stuff goes here If (Mid(obj_TargetSubFolder.Name,1,1) = "$") Then Exit Do: ' Equates to a continue for the For ' more stuff goes here Wscript.Echo obj_TargetSubFolder.Name Loop Until True: ' So the Do..Loop Next -- Steve |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Loops inside Cmdlets | PowerShell | |||
| Task manager loops back? | Vista General | |||
| FYI: 'continue' in 'for' loops is VERY slow | PowerShell | |||
| Traps and Foreach loops | PowerShell | |||
| Next fucntion in loops? | PowerShell | |||