From: Andrew FalangaDate Posted: 10/9/2008 8:52:00 AM
Hi,As you might have guessed, both from this post and the one I madeyesterday, I'm a VBScript neophyte. I'm looking on MSDN but, as yet,cannot find a construct such as 'continue' for loops. I'm assumingthat many in this forum are familiar with languages like C or Java andwill recognize this keyword.I need a way to start at the top of a For Each loop if a specificcondition is met, but can't seem to find Continue. I shall keeplooking while awaiting replies.Thanks for any help,Andy
window.google_render_ad();
Re: Is there a 'continue' construct for loops in VBScript
From: Bob Barrows [MVP]Date Posted: 10/9/2008 9:25:00 AM
Andrew Falanga wrote:> 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.>Stop looking. Change the logic in your loop so that a continue statement isn't needed. Typically an If statement is needed:for ...if ... then 'do somethingelseif ... then 'do something elseelse 'do nothing - essentially continuing the loopend ifnextSelect Case can also be used.-- Microsoft MVP - ASP/ASP.NET - 2004-2007Please reply to the newsgroup. This email account is my spam trap so Idon't check it very often. If you must reply off-line, then remove the"NO SPAM"
Re: Is there a 'continue' construct for loops in VBScript
From: mayayanaDate Posted: 10/9/2008 9:38:00 AM
Does it have to be For/Next? In a For/Nextloop you can use Exit For:For Each OFile in oFiles If oFile.Name = "SomethingOrOther.txt" then exit for'-- other ops hereNext If you can use a Do loop then you have other options.There are While and Until keywords. (Look it upin the WSH CHM help file.) There's also Exit Do:Do While x = 0'-- ops here.LoopDo If x = 0 then Exit Do'-- ops here.Loop> 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
Re: Is there a 'continue' construct for loops in VBScript
From: ekkehard.hornerDate Posted: 10/9/2008 10:14:00 AM
Andrew Falanga schrieb:> 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,> AndyIn C you can use "continue" in a loop to restrict the code followingthe "continue" statement to special cases: #include
Re: Is there a 'continue' construct for loops in VBScript
From: Andrew FalangaDate Posted: 10/9/2008 10:34:00 AM
On Oct 9, 10:10m, "ekkehard.horner" <ekkehard.hor...@arcor.de>wrote:> Andrew Falanga schrieb:>> > Hi,>> > As you might have guessed, both from this post and the one I made> > yesterday, I'm a VBScript neophyte. 'm looking on MSDN but, as yet,> > cannot find a construct such as 'continue' for loops. '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. shall keep> > looking while awaiting replies.>> > 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
Re: Is there a 'continue' construct for loops in VBScript
From: Todd VargoDate Posted: 10/9/2008 3:12:00 PM
Andrew Falanga wrote:> 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 theNext statement.For Each ... If condition = True Then Exit ForNext-- Todd Vargo(Post questions to group only. Remove "z" to email personal messages)
Re: Is there a 'continue' construct for loops in VBScript
From: Al DunbarDate Posted: 10/9/2008 10:24:00 PM
"Todd Vargo" <tlvargo@sbcglobal.netz> wrote in message news:edzFuNlKJHA.4600@TK2MSFTNGP06.phx.gbl...> Andrew Falanga wrote:>> 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> NextSounds more like he wants to abort the current iteration and go directly to 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 nextThis maps to: for each ... do some stuff before deciding if not A then do some more stuff end if nextIt 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
Re: Is there a 'continue' construct for loops in VBScript
From: SteveSinclairDate Posted: 10/12/2008 3:35:00 PM
"Andrew Falanga" <af300wsm@gmail.com> wrote in message news:17cf1f2b-2394-44b6-a691-27c518813b43@k36g2000pri.googlegroups.com...> 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,> AndyAnother approach would be to use a nested Do...Loop Until TrueFor Each obj_TargetSubFolder in col_TargetSubFoldersDo' 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..LoopNext--Steve
No comments:
Post a Comment