Posted May 1, 200916 yr 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, 200916 yr by alaphate
May 1, 200916 yr 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, 200916 yr by ghandi
May 1, 200916 yr Author 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
May 1, 200916 yr 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, 200916 yr by ghandi
Create an account or sign in to comment