# IF (statement)

Updated: 10/14/2021, 2:20:00 PM
Created: 10/14/2021, 2:20:00 PM
Last Updated By: mikes
Read Time: 2 minute(s)

Tags: if/else if/then/else if/then if not if else then if then else if then if else program control program execution

# Description

Allows for the conditional execution of some statements. It takes the general form:

IF expression THEN|ELSE statement
1

Where:

  • The expression evaluates to a value of Boolean TRUE or FALSE.
  • If the expression is TRUE, the statements defined by the THEN clause will execute (if present).
  • If the expression is FALSE, the statements defined by the ELSE clause, if any will execute.
  • The THEN and ELSE clauses may take two different forms being single and multiple line statements.

The simplest form of either clause is of the form:

IF varA THEN CRT varA
1

or

IF varA ELSE CRT varA
1

However, the END keyword may be used to expand the clauses to enclose multiple lines of code as so:

IF varA THEN
    varA = varA * 6
    CRT varA
END ELSE
    varA = 76
    CRT varA
END
1
2
3
4
5
6
7

It is possible to combine the single and multi-line versions of either clause to make complex combinations of the command. For reasons of readability it is suggested that where both clauses are present for an IF statement that the same form of each clause is coded.

IF statements can be nested within either clause to any number of levels.

An example of use is as:

CRT "Are you sure (Y/N) ":
INPUT Answer,1
IF OCONV (Answer, "MCU")= "Y" THEN
* Call delete subroutine here
    CRT "Files have been deleted"
END ELSE
    CRT "File delete was ignored"
END
1
2
3
4
5
6
7
8

Go back to jBASE BASIC

Go back to Programmers' Reference Guide