How to get out of nested loops

sarkis

Member
Licensed User
Longtime User
I have nested loops
I need to exit from both loops i.e continue from operator -xxx
Is there a simple way to do this?

For i=1 to m
For j=1 to n
if j=k Then
---- jump to -xxx
End if
Next
Next
- xxx
 

sarkis

Member
Licensed User
Longtime User
Thanks for replaying
While admac231-s answer was expected
NJDude-s answer is strange for me.
SO, we allowed to change loop index within!
For me NJDude-s solution is not acceptable because I need indexes.
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Ok, so if I understand you correctly you want to know the values of I and J, then enhancing what admac231 suggested, this is the new code:
B4X:
For I = 1 to m

    For J = 1 to n

          If J = K Then

              saveI = I
              saveJ = J
              I = m 
              Exit

          End If

    Next

Next

Now saveI and saveJ will have whatever values were assigned when exited the loop.
 
Upvote 0

sarkis

Member
Licensed User
Longtime User
these are all true.
I think the first solution, with double checking is most efficient?
Do you mind?
 
Upvote 0
Top