Loops

[ Back ]

Often you will want to repeat a number of statements a certain amount of times, until a condition is met or, even, forever. You should have a look at the Selection chapter for some information about logic expressions before you continue.

While and wend
Do and until
For, to and next
For, downto and next
Do and loop Break

While and wend

while logic expr
  statement
  ...
wend

If the logic expression evaluates to true, the statements between while and wend are performed. Every time wend is reached the logic expression is evaluated again.

Do and until

do
  statement>
  ...
until logic expr

The statements between do and until are always performed atleast once. As long as the logic expression evaluates to false, the statements are performed again.

For, to and next

for var = expr a to expr b
  statement
  ...
next

This assigns the first expression to the integer variable var. As long as var is less than or equal to the second expression, the statements between for and next are performed. var is increased by 1 every time next is reached.

For, downto and next

for var = expr a downto expr b
  statement
  ...
next

This assigns the first expression to the integer variable var. As long as var is greater than or equal to the second expression, the statements between for and next are performed. var is decreased by 1 every time next is reached.

Do and loop

do
  statement
  ...
loop

The statements between do and loop are performed until break is called or someone shuts down the program.

Break

You can leave any of the loops above by calling break.

[ Back ]