While-Loop

While condition Do statement[:statements...]

While condition [Do]
  [statement(s)]
  [Exit While]
  [statement(s)]
Wend End While



Executes a series of statements as long as a given condition is not zero (True)

Loop-block begins with While and ends with Wend or equivalently with End While keywords.
While...Wend loops can be nested to any level.
Each Wend (End While) matches the most recent While. 

The While-loop statement syntax has these parts:
  • condition : Numeric expression or string expression that evaluates to True or False. 
  • statements : Optional. One or more statements executed while condition is True. 
  • Exit While : Optional. Transfers control out of the While-Loop block.

Example:

j=0

While j<2
  i=0
  While i<3 
     i=i+1
     Print "j=";Int(j); " i=";Int(i)
     If i>1 then Exit While : 'Break loop when i=2
  End While
  j=j+1
End While



Output: 

j=0 i=1
j=0 i=2
j=1 i=1
j=1 i=2


Comments