VBA equivalent of Javascript continue

F

fazstp

Is there an equivalent of the continue used in javascript to skip a for
loop?

I have a number of if then conditions to be met and rather than nest
them I would prefer to skip to the next loop if the condition isn't
met.

ie:

For n = 1 to 10

If (condition1 = false) Then
' skip anything doesn't meet 1st criteria
' this is where I would use continue in javascript
End If

' If it gets to this point I know 1st condition has been met

If (condition2 = false) Then
' skip anything doesn't meet 2nd criteria
End If

' If it gets to this point I know 1st and 2nd conditions have been met

Next n
 
P

Pierre Archambault

Hi,

Try this:
---------------------------------------------------------------
For n = 1 to 10

If (condition1 = false) Then
Goto NextN
' skip anything doesn't meet 1st criteria
' this is where I would use continue in javascript
End If

' If it gets to this point I know 1st condition has been met

If (condition2 = false) Then
Goto NextN
' skip anything doesn't meet 2nd criteria
End If

' If it gets to this point I know 1st and 2nd conditions have been met

NextN: 'Don't forget the colon :))

Next n
 
T

Tim Williams

for n=1 to 10

if condition1=true then
if condition2= true then
'do stuff
end if
end if

next n

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top