Exit For statement - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

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