Then
Parameters
| None. |
Description
|
Marks the end of an If or ElseIf condition. Then does two different jobs depending on where it lands. On its own line it is optional decoration - If a = b Then and If a = b start exactly the same block, and most Blitz code writes it for readability. Put a statement after it, though, and it becomes the single-line form: If lives = 0 Then Restart. Now Then is doing real work, because it tells the compiler that everything following is the body of the If, complete in itself, with no EndIf to come. That form is the reason so much Blitz code fits on one screen. The same applies to ElseIf, which also takes an optional Then after its condition. Watch the mix. If you write a single-line If with Then and then add an EndIf below it, the EndIf will not match anything and the compiler will complain about a block you did not think you opened. Once a statement follows Then, that If is finished. See also: If, Else, ElseIf, EndIf, Select. |
Example
; Then Example ; ------------ ; The pilot's status after the last battle hull=65 shields=0 ; Then marks the end of the If condition - the code to run comes after it If hull>=75 Then Print "Hull at "+hull+"% - all systems go!" ElseIf hull>=40 Then Print "Hull at "+hull+"% - fly carefully out there." Else Print "Hull at "+hull+"% - return to base immediately!" End If ; In the single-line form, Then is followed directly by the command to run If shields=0 Then Print "Warning: shields are down!" Print "" Print "Press any key to close the example" WaitKey End
Index