Click to See Complete Forum and Search --> : Loops in ASP


cusimar9
02-10-2006, 11:05 AM
Is there any way I can skip to the next iteration of a While loop?

ie

i = 0
While i < 1000
if condition then skip to next

' more code
'
'
'
Loop

cusimar9
02-12-2006, 12:18 PM
Or ANY loop, in fact?

I could achieve the same effect with a bunch of nested 'IF' statements, but this would be much neater...

Master Shake
02-12-2006, 04:12 PM
Do you mean the next value of the loop iterator as in this:

i = 0
while i<1000
if somecondition Then
i = i + 1
else
normal processing
end if
i = i + 1
Loop

Is this what you mean?

Master Shake

cusimar9
02-13-2006, 02:13 AM
Well yes only I have several conditions would should end that iteration of the loop eg:

i = 0
while i < 1000
if condition1 then NextIteration
if condition2 then NextIteration
if condition3 then NextIteration
if condition4 then NextIteration
.
.
.
if condition20 then NextIteration

Some Code

i = i + 1
Loop

If Condition1 is true then there's no point checking the next 19 conditionals... just skip to the next iteration

You can do that in most languages... how do you do it in VBScript?

In C its 'Continue' for instance...

Master Shake
02-13-2006, 08:38 AM
VBSript has a case statement that maybe what you are looking for.

Select Case someexpression
Case someval
do something
Case someotherval
do somethingelse
Case onelastchoice
do alternatestuff
Case Else
do whatever
End Select

The Case Else is optional but can save you some headaches especially if you are not sure you have all the possible Cases of someexpression covered.

Master Shake

cusimar9
02-13-2006, 09:19 AM
Thanks but that doesn't really cover it either

I've managed to solve it another way though, so its ok :)