Page 109 - TechPluse_C7_Flipbook
P. 109
FOR counter = startNumber TO endNumber
Statements to repeat
Increase or decrease the counter variable
END
Where
the counter is a variable that keeps count of the number of times the instructions inside the
loop have been executed.
the startNumber is the starting number of value of the loop.
the endNumber is the total number of times the loop must run.
Let us see a program to understand the concept of FOR...NEXT statement.
Printing numbers 1 to 15
This program prints the numbers from 1 to 15 in order. The concept of increasing the value of
a variable is used in programming very often. So, most of the programming languages have a
simpler and easier way to do this. In the preceding example, the variable i contains a value that
increases by 1 each time the loop runs.
Sample Programs Using For...Next Statement
Program 1: To print even numbers up to 30.
Program 2: To print all odd numbers from 1 to 24.
Conditional and Looping Statements in BASIC-256 107

