Purpose
Defines a loop which executes as long as a specified condition evaluates as TRUE.
Syntax
While condition
statement_list
Wend
condition is a conditional expression which controls when the loop should stop.
statement_list is the group of statements to execute with each iteration of the loop.
Restrictions
You cannot issue a While...Wend statement through the MapBasic window.
Description
The While...Wend statement provides loop control. MapBasic evaluates the condition; if it is TRUE, MapBasic will execute the statement_list (and then evaluate the condition again, etc.).
As long as the condition remains TRUE, MapBasic will repeatedly execute the statement_list. When and if the condition becomes FALSE, MapBasic will skip the statement_list, and continue execution with the first statement following the Wend keyword.
Note that a statement of this form:
While condition
statement_list
Wend
is functionally identical to a statement of this form:
Do While condition
statement_list
Loop
The While...Wend syntax is provided for stylistic reasons (for example, for the sake of those programmers who prefer the While...Wend syntax over the Do...Loop statement syntax).
Example
Dim psum As Float, i As Integer
Open Table "world"
Fetch First From world
i = 1
While i <= 10
psum = psum + world.population
Fetch Next From world
i = i + 1
Wend
See Also:
Do...Loop statement, For...Next statement