' Loop with greater than comparison ' LET COUNT = 4 'Statement 1 ' DO WHILE COUNT > 0 'Statement 2 PRINT COUNT 'Statement 3 LET COUNT = COUNT - 1 'Statement 4 LOOP END
Just after Statement 1, Statement 2 will look like:
DO WHILE COUNT > 0 'Statement 2 ^ | +----- contains 4
Since 4 > 0 the condition is TRUE and the DO WHILE
lets the loop body execute.
Statement 3 and statement 4 (the loop body) execute.
After they execute, COUNT
has the value 3.
Now, since 3 > 0 the condition is TRUE (again) and the DO WHILE
lets the loop body execute
another time.
And so on.
Eventually, COUNT
is changed to zero (in statement 4).
After this happens, the condition is FALSE and the DO WHILE
will not let the loop body execute.
The program will print out:
4 3 2 1
Here is the program again, but with a small difference. What will this modified program print out?
' Modified Program ' LET COUNT = 4 'Statement 1 ' DO WHILE COUNT > 0 'Statement 2 PRINT COUNT 'Statement 3 LET COUNT = COUNT + 1 'Statement 4 LOOP END
(Hint: this is a trick question.)