What does it do?
Outer Loop:
range(1, 3) generates numbers: 1, 2
-
So, the loop runs 2 times, with i = 1 then i = 2
Inner Loop:
range(2) generates numbers: 0, 1
-
So, for each i, this inner loop runs twice, with j = 0, then j = 1
Inside Both Loops:
-
It prints the sum of i and j for each combination
Iteration Breakdown:
| i | j | i + j | Output |
|---|---|---|---|
| 1 | 0 | 1 | ✅ |
| 1 | 1 | 2 | ✅ |
| 2 | 0 | 2 | ✅ |
| 2 | 1 | 3 | ✅ |
Final Output:
Summary:
-
This is a nested loop.
-
The outer loop controls i = 1, 2
-
The inner loop controls j = 0, 1
-
The program prints the sum of i + j for each combination.


0 Comments:
Post a Comment