BASIC Programming/Beginning BASIC/Control Structures/IF...THEN...ELSEIF...ELSE

From Wikibooks, open books for an open world
Jump to: navigation, search

The IF...THEN...ELSEIF...ELSE control statement allows identifing if a certain condition is true, and executes a block of code if it is the case.

IF number<0 THEN
  PRINT "Number is negative"
ELSEIF number>0 THEN
  PRINT "Number is positive"
ELSE
  PRINT "Number is zero"
END IF

In some implementations of BASIC (put permitted by most versions), the IF statement may need to be contained in one line. However, ELSEIF may not be available in this case, and there is no need for an explicit END IF:

IF number<0 THEN PRINT "Number is negative" ELSE PRINT "Number is non-negative"
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export