alaphate Posted May 1, 2009 Posted May 1, 2009 (edited) There's no continue directive in VB6.Is this code below is the best (shortest) solution? Dim i As Integer For i = 1 To 5 If i = 3 Then GoTo CNT End If Print iCNT: Next Edited May 1, 2009 by alaphate
ghandi Posted May 1, 2009 Posted May 1, 2009 (edited) Check out this page on MSDN:http://msdn.microsoft.com/en-us/library/t2at9t47(VS.80).aspxIt explains the following snippet:Sub exitStatementDemo() Dim demoNum As Single ' Set up an infinite loop. Do For i As Integer = 1 To 10000000 demoNum = Int(Rnd() * 100) Select Case demoNum Case 7 : Exit For Case 29 : Exit Do Case 54 : Exit Sub End Select Next i LoopEnd SubBasically you can use "Exit For" to break out of a "For" loop. Im not sure how applicable this is to VB6, as i dont program in either VB6 or VB .NET.Just installed VB6 to check it out and it had a problem with declaring i as an integer if i left it as part of the For declaration and it wasnt happy with such a large integer, but changing it to:Sub exitStatementDemo() Dim demoNum As Single Dim i As Integer ' Set up an infinite loop. Do For i = 1 To 10000 demoNum = Int(Rnd() * 100) Select Case demoNum Case 7 : Exit For Case 29 : Exit Do Case 54 : Exit Sub End Select Next i LoopEnd SubThen it compiled fine...HR,Ghandi Edited May 1, 2009 by ghandi
alaphate Posted May 1, 2009 Author Posted May 1, 2009 Ghandi,Thanks for the code.However, Exit For just like c++ breakIt break out from the FOR loopIn my sample code, It will print out: 1 2 4 5and skip 3, so when i=3, it will continue the loop
ghandi Posted May 1, 2009 Posted May 1, 2009 (edited) Dim i As Integer For i = 1 To 5 If not i = 3 Then Print i End If NextIt could be done like this also. This just means that the default case isnt 3, so it will execute the code inside the "If not" statement and only jumps over the code when i=3.HR,Ghandi Edited May 1, 2009 by ghandi
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now