Statements and Functions

This topic describes the differences between statements and functions in BASIC and provides working definitions of variables, constants, labels, spaces, and program formatting.

If the syntax requires that the instruction be followed by a set of parentheses (optionally containing an argument or arguments), then it is a function. For example, these are functions:

abs(num.exp)

rnd(num.exp)

iconv(str.exp, conv.exp)

Any instruction that does not have to be followed by a set of parentheses is most often a statement. For example:

print x

input y

execute sentence

There is at least one exception to the above rule. One variation of the locate() function is considered a statement, even though the format of the syntax is like a function.

Another feature of statements is that they tend to stand alone. For example:

execute sentence

print array<10,1>

Functions, by contrast, do not stand alone. They are either used as part of an expression within a statement:

"raise = rnd(20)"

or output immediately:

"crt int(amount)", "print abs(balance)"

A BASIC program is composed of statements made up of variables, constants, expressions, and functions.

BASIC statements can contain arithmetic, relational, and logical expressions. These expressions are formed by combining specific operators with variables, constants, or BASIC intrinsic functions.

The value of a variable can change dynamically throughout the execution of a program. A constant, as its name implies, has the same value throughout the execution of a program.

An intrinsic function performs a predefined operation on the supplied parameters. In BASIC programs, each physical line usually contains only one statement. This is done for ease of reading and tracking of logic.

More than one statement can be placed on a program line by separating each statement with a ; (semicolon). Statements that end with then or else on a line create a block or multiline structure.

Labels can be placed at the beginning of any BASIC statement. A statement label can be numeric or alphanumeric.

Spaces appearing in the program line that are not part of a literal are ignored. Spaces and blank lines can be used freely within the program for purposes of appearance.