OUTPUTS FOR 20 LOOP SNIPPETS
1
for (int i = 0; i < 5; i++, [Link]("X")) {
[Link](i);
}
Output:
0
X
1
X
2
X
3
X
4
X
2
1*5=5
2*4=8
3*3=9
Output:
5
8
9
3
Condition: stop when i % 3 == 0
Starts at 10 → 10 % 3 = 1 → ok
9 % 3 = 0 → STOP (9 is not printed)
Output:
10
4
(x < y)
Pairs:
0 20
3 16
6 12
9 8 → next: x=12,y=4 → 12<4 false
Output:
0 20
3 16
6 12
98
5
i = 1 → j = 3,2,1 → (4,3,2)
i = 2 → j = 3,2,1 → (5,4,3)
i = 3 → j = 3,2,1 → (6,5,4)
Output:
4
3
2
5
4
3
6
5
4
6
Loop does nothing. Only prints:
Done
7
Even i values → 2,4 → print i*2
Output:
4
8
8
i=1→0
i=4→3
i=7→6
i = 10 → 9
Output:
0
3
6
9
9
i=5,j=1 → 4
i=4,j=3 → 1
i=3,j=5 → STOP (j<i false)
Output:
4
1
10
i=1 → j=1,2,3 → 1,2,3
i=2 → j=2,3 → 4,6
i=3 → j=3 → 9
Output:
1
2
3
4
6
9
11
Stop when i%4==0 → stops at i=4 (4 not printed)
Output:
1
2
3
12
i=0,j=0 → 0
i=1,j=2 → 3
i=2,j=4 → 6
Next: i=3,j=6 → 3+6=9 <5? false
Output:
0
3
6
13
Just prints 0,1,2
Output:
0
1
2
14
Squares of 1–5
Output:
1
4
9
16
25
15
i=3 → j=1,2 → 4,5
i=2 → j=1 → 3
i=1 → j<1 → none
Output:
4
5
3
16
i=2,j=8 → 28
i=4,j=5 → 45
i=6,j=2 → 62
next: i=8,j=-1 → j>0 false
Output:
28
45
62
17
Runs 4 times: prints i before increment
Output:
1
2
3
4
18
Loop ends when i2 < 15 becomes false
i goes from 1→2→3→4→5→6→7→8
At i=8: 82=16 → stops → i=8
Output:
8
19
i=1 → (1+1)=2
i=2 → (2+1)=3, (2+2)=4
i=3 → (3+1)=4, (3+2)=5, (3+3)=6
Output:
2
3
4
4
5
6
20
Break when i==4 (4 not printed)
Output:
1
2
3