W wes58 Active Member Licensed User Longtime User Jan 5, 2011 #1 I have the following sample code: For i = 0 To 10 l = j(i) if l > 20 then 'I want to exit the loop end if Next Click to expand... How can I exit the loop if certain conditions are met. Normally you would use "Exit For" statement in For loop but it doesn't work here. I know I could change the value of i to max. value when I get into the "If... end if" code but I need to know the value of i that stopped the For loop in the rest of the code? I guess I could assign value of i inside "If ... end if" to another variable before changing it to max value but that complicates the code (unnecessary). The same is with While loop
I have the following sample code: For i = 0 To 10 l = j(i) if l > 20 then 'I want to exit the loop end if Next Click to expand... How can I exit the loop if certain conditions are met. Normally you would use "Exit For" statement in For loop but it doesn't work here. I know I could change the value of i to max. value when I get into the "If... end if" code but I need to know the value of i that stopped the For loop in the rest of the code? I guess I could assign value of i inside "If ... end if" to another variable before changing it to max value but that complicates the code (unnecessary). The same is with While loop
JesseW Active Member Licensed User Longtime User Jan 5, 2011 #2 It's not Exit For, it's just Exit in B4A. It exits the inner most loop, no matter the structure (ie. For Next, Do Loop, Sub, etc..) I ran across this myself.. Upvote 0
It's not Exit For, it's just Exit in B4A. It exits the inner most loop, no matter the structure (ie. For Next, Do Loop, Sub, etc..) I ran across this myself..
W wes58 Active Member Licensed User Longtime User Jan 5, 2011 #3 JesseW said: It's not Exit For, it's just Exit in B4A. It exits the inner most loop, no matter the structure (ie. For Next, Do Loop, Sub, etc..) I ran across this myself.. Click to expand... Thanks for that. Upvote 0
JesseW said: It's not Exit For, it's just Exit in B4A. It exits the inner most loop, no matter the structure (ie. For Next, Do Loop, Sub, etc..) I ran across this myself.. Click to expand... Thanks for that.
S shaxboz Member Licensed User Longtime User Mar 29, 2014 #4 Hi! How can I count down with for...next? Upvote 0
DonManfred Expert Licensed User Longtime User Mar 29, 2014 #5 Code: Copy For i = 100 To 0 Step -1 ' do something next Upvote 0
eps Expert Licensed User Longtime User Mar 29, 2014 #6 You could also use Return to leave the loop. e.g. http://www.b4x.com/android/forum/threads/breaking-from-subroutines-loops.35049/ Upvote 0
You could also use Return to leave the loop. e.g. http://www.b4x.com/android/forum/threads/breaking-from-subroutines-loops.35049/