EasyManua.ls Logo

Commodore 128 - Exit; The BEGIN;BEND Sequence with IF-THEN; The else Clause with IF-THEN

Commodore 128
448 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
EXIT
An EXIT statement can be placed within the body of a DO/LOOP.
When the EXIT statement Is encountered, the program jumps to
the next statement following the LOOP statement.
The ELSE clause with IF-THEN
The ELSE clause provides a way to tell the computer how to
respond if the condition of the IF-THEN statement is false. Rather
than continuing to the next program line, the computer will
execute the command or branch to the program line mentioned
in the ELSE clause. For example, if you wanted the computer to
print the square of a number, you could use the ELSE clause like
this:
10 INPUT TYPE A NUMBER TO BE SQUARED;N
20 IF N< 100 THEN PRINT N*N: ELSE 40
30 END
40 ?NUMBER MUST BE < 100: GOTO 10
Notice that you must use a colon between the IF-THEN
statement and the ELSE clause.
The BEGIN/BEND Sequence with IF-THEN
BASIC 7.0 allows you to take the IF-THEN condition one step
further. The BEGIN/BEND sequence permits you to include a
number of program lines to be executed if the IF condition is true,
rather than one simple action or GOTO. The command is
constructed like this:
IF condition THEN BEGIN:
(program lines):
BEND:ELSE
Be sure to place a colon between BEGIN and any instructions to
the computer, and again between the last command in the
sequence and the word BEND. BEGIN/BEND can be used
without an ELSE clause, or can be used following the ELSE
clause when only a single command follows THEN. Try this
program:
5-5

Table of Contents

Other manuals for Commodore 128

Related product manuals