For ... Next, Do While... Loop

wes58

Active Member
Licensed User
Longtime User
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

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
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

DonManfred

Expert
Licensed User
Longtime User
B4X:
For i = 100 To 0 Step -1
  ' do something
next
 
Upvote 0
Top