' Mystery Program ' LET ENDVALUE = 5 LET COUNT = 1 DO WHILE COUNT <= ENDVALUE PRINT "Hello" LET COUNT = COUNT + 1 LOOP ' END
will print out:
Hello Hello Hello Hello Hello
There are 5 "Hellos", corresponding to the value 5 in ENDVALUE
.
An INPUT
statement can read
a number from the user.
It could put the number into ENDVALUE
.
If this is done, the user can say how many times
the loop should execute.
Let us change the program so that the user
enters a number, and then that many "Hellos"
are PRINT
ed.
Here is how the program gets a number from the user:
PRINT "How many times do you want to print Hello" INPUT ENDVALUE
Here is the program (with a gap or two):
' Almost complete program ' LET COUNT = 1 DO WHILE COUNT <= ENDVALUE PRINT "Hello" LET COUNT = COUNT + 1 LOOP END
Mentally insert the two statements into the above program so that the user determines how many times the loop executes.