Structured Programming in Basic Problems
© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved
Instructions: Review the following program and see if you can predict the outcome by completing a "pencil trace" of the code. Program output is provided at the end of this page. Compiler: The program was prepared using GWBasic, which requires the use of line numbers.
10 REM This program demonstrates a nested loop.
20 FOR X = 2 TO 3
30 FOR Y = 4 TO 5
40 FOR Z = 6 TO 7
50 PRINT X Y Z
60 NEXT Z
70 NEXT Y
80 NEXT X
99 END
10000 REM And the answer is ...
10010 REM 2 4 6
10020 REM 2 4 7
10030 REM 2 5 6
10040 REM 2 5 7
10050 REM 3 4 6
10060 REM 3 4 7
10070 REM 3 5 6
10080 REM 3 5 7