Blitz3D+ Command Reference

EndIf

Parameters

None.

Description

Closes a multi-line If block.

Everything between If and its EndIf belongs to the block, including any ElseIf and Else branches. One EndIf closes the whole chain, however many branches it has.

It can also be written as two words - see End If - with no difference in behaviour.

The single-line form of If needs no EndIf at all. If lives = 0 Then GameOver is complete on its own line, and adding an EndIf underneath it will give you a compile error about a block that was never opened.

Nested Ifs each need their own EndIf, matched innermost first. A missing one usually shows up as an error a long way down the file, where the compiler finally runs out of program, so keeping your indentation honest saves a lot of hunting.

See also: If, End If, Else, ElseIf, Then.

Example

; EndIf Example
; -------------

; The pilot's status after the last battle
hull=65

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!"
; EndIf closes the whole If block (it may also be written as End If)
EndIf

Print ""
Print "Press any key to close the example"
WaitKey

End

Index