5.2 Looping | 239
We’ll keep track of the variables line,starCount, and loopCount, as well as the logical expres-
sions. To do so, we’ve numbered each line (except lines containing only a brace). As we trace
the code, we indicate the first execution of line 3 by 3.1, the second by 3.2, and so on. Each
loop iteration is enclosed by a large brace, and trueand falseare abbreviated as T and F (see
Table 5.1).
Variables Logical Expressions
Statement line starCount loopCount line != null loopCount <= starCount Output
1.1 ‘3’ — — — — —
2.1 ‘3’ — — T — —
3.1 ‘3’ 3 — — — —
4.1 ‘3’ 3 1 — — —
5.1 ‘3’ 3 1 — T —
6.1 ‘3’ 3 1 — — *
7.1 ‘3’ 3 2 — — —
5.2 ‘3’ 3 2 — T —
6.2 ‘3’ 3 2 — — *
7.2 ‘3’ 3 3 — — —
5.3 ‘3’ 3 3 — T —
6.3 ‘3’ 3 3 — — *
7.3 ‘3’ 3 4 — — —
5.4 ‘3’ 3 4 — F —
8.1 ‘3’ 3 4 — — \n(newline)
9.1 ‘1’ 3 4 — — —
2.2 ‘1’ 3 4 T — —
3.2 ‘1’ 1 4 — — —
4.2 ‘1’ 1 1 — — —
5.5 ‘1’ 1 1 — T —
6.4 ‘1’ 1 1 — — *
7.4 ‘1’ 1 2 — — —
5.6 ‘1’ 1 2 — F —
8.2 ‘1’ 1 2 — — \n(newline)
9.2 null 1 2 — — —
2.3 null 1 2 F — —
10.1 null 1 2 — — End
Table 5.1 Code Trace