The I F Statement - IBM 5110 Basic Introduction

Table of Contents

Advertisement

c
' ' ' · . · . ~ . · ·
v
(
...•
,.
\
. /
c
c
The I F Statement
An IF statement can test whether a variable is equal to, greater than,
or less than another variable or constant of the same data type. The
I F statement includes a GOTO statement. The I F statement operates
this way:
1.
The IF statement tests the condition you define.
2.
If the answer to the test is yes, the condition is true; the system
will go to the line number that you entered in the I F statement.
3.
If the answer is
no,
the system ignores the rest of the IF
statement and goes directly to the next sequential line in the
program.
Here's an example of an IF statement:
0040 IF
X=O
GOTO 80
In this statement, if X is ·0, the system goes to line 80. If X is
not
0, it
goes on to the next line in the program.
The six tests you can make with the IF statement are:
• Equal to,
=
• Not equal to,
;t
or
< >
• Greater than, >
• Less than,
<
• Greater than or equal to,
~
or >
=
• Less than or equal to,
~
or <
=
The system stores
< >
as
;t,
>=
as
~,
and
< =
as
~;
thus, even though
you enter
< >
the system will display
;t
when you list the statements.
How to Write a Program
53
c
' ' ' · . · . ~ . · ·
v
(
...•
,.
\
. /
c
c
The I F Statement
An IF statement can test whether a variable is equal to, greater than,
or less than another variable or constant of the same data type. The
I F statement includes a GOTO statement. The I F statement operates
this way:
1.
The IF statement tests the condition you define.
2.
If the answer to the test is yes, the condition is true; the system
will go to the line number that you entered in the I F statement.
3.
If the answer is
no,
the system ignores the rest of the IF
statement and goes directly to the next sequential line in the
program.
Here's an example of an IF statement:
0040 IF
X=O
GOTO 80
In this statement, if X is ·0, the system goes to line 80. If X is
not
0, it
goes on to the next line in the program.
The six tests you can make with the IF statement are:
• Equal to,
=
• Not equal to,
;t
or
< >
• Greater than, >
• Less than,
<
• Greater than or equal to,
~
or >
=
• Less than or equal to,
~
or <
=
The system stores
< >
as
;t,
>=
as
~,
and
< =
as
~;
thus, even though
you enter
< >
the system will display
;t
when you list the statements.
How to Write a Program
53

Advertisement

Table of Contents
loading

Table of Contents