Purpose
Exits a For...Next statement prematurely.
Restrictions
You cannot issue an Exit For statement through the MapBasic window.
Syntax
Exit For
Description
An Exit For statement terminates a For...Next statement. Upon encountering an Exit For statement, MapBasic will jump to the first statement following the For...Next statement. Note that the Exit For statement is only valid within a For...Next statement.
For...Next statements can be nested; that is, a For...Next statement can appear within the body of another, "outer" For...Next statement. Note that an Exit For statement only halts the iteration of the nearest For...Next statement. Thus, in an arrangement of this sort:
For x = 1 to 5
:
For y = 2 to 10 step 2
:
If error_condition
Exit For
End If
:
Next
:
Next
the Exit For statement will halt the inner loop (For y = 2 to 10 step 2) without necessarily affecting the outer loop (For x = 1 to 5).
See Also:
Exit Do statement, For...Next statement