Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm looking for a for loop like the below
VB
dim i as integer
dim j as integer = 5

For i = 0 To j
   If i = 5 Then
        i = 10
        j = 20
   End If

Next

if i=5 then I want to increment i to 10 and j to 20, so that loop will extend to 10 to 20

can anyone suggest me how to accomplish this.
Posted
Comments
Thanks7872 18-Jul-13 1:03am    
no
Sergey Alexandrovich Kryukov 18-Jul-13 1:05am    
Never modify a loop variable inside a loop body. The question is incorrect. You cannot "want" to increment a loop variable, you want to get some effect, but you are not asking about it. It simply makes no sense.
—SA

1 solution

I think this will help

VB
        Dim i As Integer
        Dim j As Integer = 5
        Dim k As Integer

NextLoop:
        For i = k To j
            If i = 5 Then
                k = 10
                j = 20
                GoTo NextLoop
            End If
        Next
 
Share this answer
 
Comments
cyanceenu 18-Jul-13 1:49am    
xlent.. thanks for the suggestion...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900