Explanation:
Initialization
i = 3
The variable i is set to 3.
This will be the starting value for the loop.
While Loop Condition
while i > 1:
The loop will keep running as long as i is greater than 1.
First iteration → i = 3 → condition TRUE
Second iteration → i = 2 → condition TRUE
Third time → i = 1 → condition FALSE → loop stops
Inner For Loop
for j in range(2):
range(2) gives values 0 and 1.
This means the inner loop runs 2 times for each while loop cycle.
Print Statement
print(i - j, end=" ")
This prints the result of i - j each time.
When i = 3:
j = 0 → prints 3
j = 1 → prints 2
When i = 2:
j = 0 → prints 2
j = 1 → prints 1
Decrease i
i -= 1
After each full inner loop, i is decreased by 1.
i = 3 → becomes 2
i = 2 → becomes 1
Now i = 1 → while loop stops.
Final Output
3 2 2 1


0 Comments:
Post a Comment