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,
> 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) ===