QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

ELSE is used in IF…THEN or SELECT CASE statements to offer an alternative to other conditional statements.

Syntax

Single-line syntax:

IF condition THEN {code} ELSE {alternative-code}

Block syntax:

IF condition THEN

{code}

ELSEIF condition2 THEN {code}

ELSE {alternative-code}

END IF

Description

Example(s)

One line IF statement


IF x = 100 THEN PRINT "100" ELSE PRINT "Not 100"


Multiple line IF statement block


IF x = 100 THEN ' code executed MUST be on next statement line!
   PRINT "100"
ELSE PRINT "Not 100"
END IF


To alternate between any two values (as long as the value after ELSE is the same as the condition)


IF a = 3 THEN a = 5 ELSE a = 3


See Also