|
condition - the next expression to test if the previous branches failed Then (optional) - readability only; ElseIf always opens a block |
|
Tests another condition when the previous If or ElseIf was false. ElseIf chains decisions without nesting them. Each branch is tried in order, the first one whose condition is true runs, and the rest are skipped entirely: If hull >= 75 status$ = "good" ElseIf hull >= 40 status$ = "damaged" Else status$ = "critical" EndIf Because branches are tested in order, ordering matters: put the tighter conditions first, or a broader one above will swallow them. You can write it as two words - see Else If - and the two forms behave identically. Long ElseIf ladders get hard to follow. When you are testing the same value against several fixed alternatives, Select and Case say the same thing more clearly, and Select True lets you keep full conditions in each Case. See also: If, Else If, Else, EndIf, Select. |
; ElseIf Example
; --------------
; The pilot's status after the last battle
hull=65
; ElseIf checks a further condition when the ones above it failed
If hull>=75 Then
Print "Hull at "+hull+"% - all systems go!"
ElseIf hull>=40 Then
Print "Hull at "+hull+"% - fly carefully out there."
ElseIf hull>=10 Then
Print "Hull at "+hull+"% - return to base immediately!"
Else
Print "Hull at "+hull+"% - eject! Eject!"
End If
Print ""
Print "Press any key to close the example"
WaitKey
End