' Draw 100 circles, each in a new color ' (buggy program) ' SCREEN 12 ' LET HUE = 4 LET COUNT = 1 ' DO WHILE COUNT <= 100 ' LET HUE = HUE + 1 COLOR HUE CIRCLE (320, 240),50 SLEEP 1 ' LET COUNT = COUNT + 1 LOOP ' END
The program is nearly OK, but it has a bug.
Each time the loop body executes, HUE
is increased by one, the current pen color is set
to HUE
, and the new circle is drawn.
But look what happens when HUE gets up to 15:
LET HUE = HUE + 1 ' HUE changes from 15 to 16 COLOR HUE ' pen color set to 16 ' but there is no color 16--- ' CRASH!! CIRCLE (320, 240),50 SLEEP 1
The program will work fine for a while, but since each execution of
the loop body increases HUE
by one,
HUE
will get too big for the
system to handle long before the 100 circles have been drawn.
(Thought Question:) Instead of changing HUE
to 16, what else could you do?