ELSEIF: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "ELSEIF is used in an IF...THEN block statement to offer an alternative condition. {{PageSyntax}} : IF {{Parameter|condition}} THEN :: ''{code}'' :: ⋮ : ELSEIF {{Parameter|condition2}} THEN :: ''{code}'' :: ⋮ : ELSE :: ''{alternative-code}'' :: ⋮ : END IF {{PageDescription}} * ELSEIF statements require a '''separate''' code block line with THEN for each alternative condition. * There can be more than one ELSE IF statement...") |
No edit summary |
||
Line 23: | Line 23: | ||
{{ | {{RelationalTable}} | ||
Revision as of 12:40, 5 June 2022
ELSEIF is used in an IF...THEN block statement to offer an alternative condition.
Syntax
Description
- ELSEIF statements require a separate code block line with THEN for each alternative condition.
- There can be more than one ELSE IF statement in a single-line IF statement.
- If there is only one possible alternative condition (such as 0 or NOT 0), use ELSE instead.
- If the comparisons are based on multiple conditions being true, it may require many ELSEIF comparisons. ELSE could help cover some of those conditions.
- You can use SELECT CASE when IF blocks have a long list of alterative ELSEIF conditions.
Examples
Example 1: IF statement using ELSE IF in one statement line.
IF x = 100 THEN COLOR 10: PRINT x ELSE IF x > 100 THEN COLOR 12: PRINT x ELSE PRINT "< 100" |
Example 2: IF statement block
IF x = 100 THEN ' must place ANY code on next line! COLOR 10: PRINT x ELSEIF x > 100 THEN COLOR 12: PRINT x ELSE : PRINT "< 100" END IF |
See also