ELSEIF - QB64 Wiki

ELSEIF

From QB64 Wiki

Jump to: navigation, search

ELSEIF is used in a block IF...THEN statement to offer an alternative condition.


Block Syntax:

IF condition > 0 THEN
evaluation = -1
ELSEIF condition < 0 THEN evaluation = -1
ELSE evaluation = 0
END IF


  • 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), then 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.


Relational Operators:
Symbol Condition Example Usage
<  Less than  IF a < b THEN
>  Greater than  IF a > b THEN
=  Equal  IF a = b THEN
<=  Less than or equal  IF a <= b THEN
>=  Greater than or equal  IF a >= b THEN
<>  NOT equal  IF a <> b THEN


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:




Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Views
Personal tools