BASIC6.WPS

BASIC LANGUAGE PROGRAMMING

USING FOR/NEXT LOOPS

In the last assignment we learned how to enter, save run and

print out programs and their generated data. The program you

entered in the last assignment used a system called the FOR/NEXT

loop in order to get the program to loop back

upon itself X times. Huge amounts of data can be generated using

extremely short programs by using this technique.

Here are three examples of properly constructed FOR/NEXT

loops:

EXAMPLE #1

FOR COUNT = 1 TO 10

NEXT COUNT

 

EXAMPLE #2 (THIS LOOP COUNTS UP IN STEPS OF 5)

FOR COUNT = 1 TO 100 STEP5

NEXT COUNT

 

EXAMPLE #3 ( THIS LOOP COUNTS DOWN IN SINGLE STEPS)

FOR COUNT = 10 TO 1 STEP -1

NEXT COUNT

ASSIGNMENT

1) Write a program which uses a FOR/NEXT loop to count

from 1 to 50 and print the number out on each loop.

Print a copy of the program and use the LPRINT

command in the program to direct the program print

out to the printer. Staple these two sheets together.

2) Write a program which uses a FOR/NEXT loop to count

from 1 to 100 in steps of 2 and print the number out

on each loop. Print a copy of the program and use the

LPRINT command in the program to direct the program print

out to the printer. Staple these two sheets together.

 

 

3) Write a program which uses a FOR/NEXT loop to count

from 100 to 20 in steps of -2 and print the number out

on each loop. Print a copy of the program and use the

LPRINT command in the program to direct the program print

out to the printer. Staple these two sheets together.

4) Staple together the 6 printouts associated with this

assignment and hand them in together.

Copyright - Barry Boyle (bboyle@kawartha.net)