1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-01 15:00:38 +00:00
QB64-PE/internal/help/ELSE.txt

64 lines
1.4 KiB
Plaintext
Raw Normal View History

2017-10-10 14:55:21 +00:00
[[ELSE]] is used in [[IF...THEN]] or [[SELECT CASE]] statements to offer an alternative to other conditional statements.
{{PageSyntax}}
2017-10-10 14:55:21 +00:00
''Single-line syntax:''
: [[IF]] {{Parameter|condition}} [[THEN]] ''{code}'' [[ELSE]] ''{alternative-code}''
2017-10-10 14:55:21 +00:00
''Block syntax:''
: [[IF]] {{Parameter|condition}} [[THEN]]
:: ''{code}''
:: ⋮
: [[ELSEIF]] {{Parameter|condition2}} [[THEN]]
:: ''{code}''
:: ⋮
: [[ELSE]]
:: ''{alternative-code}''
:: ⋮
: [[END IF]]
2017-10-10 14:55:21 +00:00
{{PageDescription}}
* ELSE is used in a IF block statement to cover any remaining conditions not covered in the main block by IF or [[ELSEIF]].
* [[CASE ELSE]] covers any remaining conditions not covered by the other CASE statements.
2017-10-10 14:55:21 +00:00
* ELSE can also be used as a false comparison to a true IF statement when a condition will only be true or false.
* Other [[IF...THEN]] statements can be inside of an ELSE statement.
2017-10-10 14:55:21 +00:00
{{PageExamples}}
''Example 1:'' One line IF statement
{{CodeStart}}
2019-04-15 01:15:33 +00:00
IF x = 100 THEN PRINT "100" ELSE PRINT "Not 100"
{{CodeEnd}}
''Example 2:'' Multiple line IF statement block
{{CodeStart}}
IF x = 100 THEN ' code executed MUST be on next statement line!
2019-04-15 01:15:33 +00:00
PRINT "100"
ELSE PRINT "Not 100"
END IF
{{CodeEnd}}
''Example 3:'' To alternate between any two values (as long as the value after ELSE is the same as the condition)
{{CodeStart}}
IF a = 3 THEN a = 5 ELSE a = 3
{{CodeEnd}}
2017-10-10 14:55:21 +00:00
{{PageSeeAlso}}
* [[ELSEIF]]
* [[IF...THEN]]
2019-04-15 01:15:33 +00:00
{{PageNavigation}}
<