IBM 5110 Basic Introduction page 65

Table of Contents

Advertisement

C:t
c
c
Then you tell the system to go to the next value of X and repeat the
loop:
0040 NEXT X
FOR and NEXT statements always go in pairs: FOR at the beginning
of the loop and NEXT at the end. The system automatically repeats
the loop as many times as you told it to in the FOR statement. When
it finishes, it goes on to the statement following the NEXT statement.
Using the FOR and NEXT statements, the rug program looks like this:
0010 FOR X=9 TO 20
0020 Y=(12*X)/9
0030 PRINT X,Y
0040 NEXT X
0050 STOP
In a FOR statement, you can name any arithmetic variable to be the
control variable, and you can make its range of values anything you
want. The control var¢iable is to the left of the equal sign. The range
(to the right of the equal sign) doesn't have to be given in numbers.
You can use other variables for the range, for example:
0060 FOR J=A TO B
0120 NEXT J
Steps
When you write a FOR statement, the system increases the value in
steps of 1 (for example, 1 to 2 to 3, or 18 to 19 to 20 to 21).
However, sometimes you may want to use just even numbers, or odd
numbers, or every tenth number. If your loop requires a value other
than steps of 1, you can specify the step value whether you are using
FOR and NEXT statements or a LET statement to control the loop.
If you write a loop that uses a LET statement, you can write these LET
statements:
0100 X=X+2
To change X in steps of 2
0050 X=X+10
To change X in steps of
10
How to Write a Program
61
C:t
c
c
Then you tell the system to go to the next value of X and repeat the
loop:
0040 NEXT X
FOR and NEXT statements always go in pairs: FOR at the beginning
of the loop and NEXT at the end. The system automatically repeats
the loop as many times as you told it to in the FOR statement. When
it finishes, it goes on to the statement following the NEXT statement.
Using the FOR and NEXT statements, the rug program looks like this:
0010 FOR X=9 TO 20
0020 Y=(12*X)/9
0030 PRINT X,Y
0040 NEXT X
0050 STOP
In a FOR statement, you can name any arithmetic variable to be the
control variable, and you can make its range of values anything you
want. The control var¢iable is to the left of the equal sign. The range
(to the right of the equal sign) doesn't have to be given in numbers.
You can use other variables for the range, for example:
0060 FOR J=A TO B
0120 NEXT J
Steps
When you write a FOR statement, the system increases the value in
steps of 1 (for example, 1 to 2 to 3, or 18 to 19 to 20 to 21).
However, sometimes you may want to use just even numbers, or odd
numbers, or every tenth number. If your loop requires a value other
than steps of 1, you can specify the step value whether you are using
FOR and NEXT statements or a LET statement to control the loop.
If you write a loop that uses a LET statement, you can write these LET
statements:
0100 X=X+2
To change X in steps of 2
0050 X=X+10
To change X in steps of
10
How to Write a Program
61

Advertisement

Table of Contents
loading

Table of Contents