S sarkis Member Licensed User Longtime User Apr 4, 2012 #1 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
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
A admac231 Active Member Licensed User Longtime User Apr 4, 2012 #2 Using multiple If statements would be easiest. So: B4X: For i=1 To m For j=1 To n If j=k Then Exit End If Next If j=k Then Exit End If Next Upvote 0
Using multiple If statements would be easiest. So: B4X: For i=1 To m For j=1 To n If j=k Then Exit End If Next If j=k Then Exit End If Next
NJDude Expert Licensed User Longtime User Apr 4, 2012 #3 Something like this: B4X: For I = 1 to m For J = 1 to n If J = K Then I = m Exit End If Next Next Last edited: Apr 4, 2012 Upvote 0
S sarkis Member Licensed User Longtime User Apr 4, 2012 #4 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: Apr 4, 2012 Upvote 0
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.
NJDude Expert Licensed User Longtime User Apr 4, 2012 #5 For me NJDude-s solution is not acceptable because I need indexes. Click to expand... What do you mean by "indexes"? Upvote 0
For me NJDude-s solution is not acceptable because I need indexes. Click to expand... What do you mean by "indexes"?
A admac231 Active Member Licensed User Longtime User Apr 4, 2012 #6 NJDude said: What do you mean by "indexes"? Click to expand... This confuses me also. I would say NJDudes solution is superior to mine. Upvote 0
NJDude said: What do you mean by "indexes"? Click to expand... This confuses me also. I would say NJDudes solution is superior to mine.
A admac231 Active Member Licensed User Longtime User Apr 4, 2012 #8 Well in this case J = K so you can use that elsewhere and you could set I to be another variable and use it elsewhere. B4X: If J = K Then I = tmpVar I = m Exit End If Upvote 0
Well in this case J = K so you can use that elsewhere and you could set I to be another variable and use it elsewhere. B4X: If J = K Then I = tmpVar I = m Exit End If
NJDude Expert Licensed User Longtime User Apr 4, 2012 #9 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
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.
S sarkis Member Licensed User Longtime User Apr 4, 2012 #10 these are all true. I think the first solution, with double checking is most efficient? Do you mind? Upvote 0