Program Flow

While/Wend loops

A While/Wend loop continues executing while an expression evaluates to true.
While Expression
  Statements...
Wend

Repeat/Until loops

A Repeat/Until loop continues executing until an expression evaluates to true.

The body of a Repeat/Until loop will generally execute at least once, as the loop termination expression is not checked until the end of the loop.
Repeat
  Statements...
Until Expression

Repeat/Forever loops

A Repeat/Forever loop will continue executing until an Exit statement is executed somewhere inside the loop.
Repeat
  Statements...
Forever

For/To/Next loops

A For/To/Next loop will continue executing until the value of a numeric index variable goes beyond an exit value. The index variable is automatically updated every loop iteration by adding a step value. Note that the exit value is inclusive - the loop will typically execute once with the index variable equal to the exit value before terminating.
For IndexVariable=StartValue To ExitValue Step StepValue   Statements...
Next
The 'Step' part is optional, in which case the index variable will step in increments of 1. The step value must also be constant.

The exit value is only evaluated once at the start of the loop. This means it is safe to use complex or 'slow' code as an exit value.

You may also declare a new local variable to be used as the index variable, by preceding the index variable with the Local keyword. Such local variables will not be visible outside of the loop when it terminates.

For/Until/Next loops

A For/Until/Next loop operates in a similar manner to a For/To/Next loop, except that the loop will terminate when the index variables becomes equal to the exit value - in other words, the exit value is exclusive. This can be useful when you need to count 'up to' a value, without actually including that value.
For IndexVariable=StartValue Until ExitValue Step StepValue   Statements...
Next
The 'Step' part is optional, in which case the index variable will step in increments of 1. The step value must also be constant.

The exit value is only evaluated once at the start of the loop. This means it is safe to use complex or 'slow' code as an exit value.

You may also declare a new local variable to be used as the index variable, by preceding the index variable with the Local keyword. Such local variables will not be visible outside of the loop when it terminates.

Exit and Continue

The Exit command can be used to exit from a While, Repeat or For loop. The loop will be terminated, and program flow will be transferred to the first command after the loop.

The Continue command can be used to force a While, Repeat or For loop to continue execution, skipping any commands which would normally have been executed before the loop was continued.

Both Exit and Continue may be followed by an optional identifier. This identifer must match a previously declared loop label, which allows you to exit or continue a specific loop, not necessarily the 'nearest' loop.

To declare a loop label, use the syntax #Identifier immediately preceding a While, Repeat or For loop. For example, this program will exit both loops when k and j both equal 5:
Strict
Local k,j
#Label1   'loop label
For k=1 To 4
  #Label2    'another loop label (unused in this example)
  For j=1 To 4
    Print k+","+j
    If k=3 And j=3 Exit Label1
  Next
Next
Note that loop labels are only available in strict mode. In non-strict mode, use Goto instead.

If/Then blocks

BlitzMax provides both the classic BASIC 'one liner' style of If/Then statement, and the more modern block equivalent.
If Expression Then Statements... Else Statements...
If Expression
  Statements..
Else If Expression
  Statements..
Else Expression
  Statements..
EndIf
In both forms, the Then keyword is optional.

Select/Case blocks

A Select/Case block allows you to simplify complex conditional tests. The select expression is compared with each of the case expressions and, if found to be equal, the program code within the appropriate case block is executed. If no matching case is found, the program code within the optional default block is executed.
Select Expression
Case Expressions..
  Statements..
Default
  Statements..
End Select
The default part is optional.

The select value is only evaluated once, before each case is checked.

Multiple expressions for each case may be used by providing a comma separated sequence of expressions.