EXIT SUB/FUNCTION is the same as RETURN but unable to return a “value”
EXIT DO/WHILE only exit their own loop and cannot exit an outter loop?
EXIT FOR (without a variable) only exit their own loop and cannot exit an outter loop?
EXIT FOR x … exits the x loop regardless of nested loops
For i=1 to 10
for j=1 to 10
Exit For // exits only the J loop
Next j
Next i
For i=1 to 10
for j=1 to 10
Exit For i // exits the I (outter)
Next j
Next i
For i=1 to 10
While j<10
j=j+1
If j=5 Then Exit While
Wend
Next i
Making only #4 the most “complex” … the rest just require replacement with either “RETURN” or “BREAK” in Swift
If your working on Xojo to Swift code conversion, then don’t forget Swift for loops can be labeled, and exited from inner nested loops, using the break keyword, like this.
outerLoop: for i in 1...20 {
if i % 2 != 0 { // If odd number
continue // Next iteration of outerLoop
}
innerLoop: for x in 1...5 {
if i > 10 { // i is higher than 10
break outerLoop // Exit outerLoop
}
print("\(i) + \(x) = \(i + x)")
}
}
Yes, I was aware… which is actually why I stated the question the way I did… to be sure the the only time I should need that construct is where a “EXIT FOR” included a variable relating to an outer loop