Code Explanation:
๐น Loop Setup (range(3))
range(3) creates values: 0, 1, 2
The loop will run 3 times
๐น Iteration 1
i = 0
print(i) → prints 0
i = 5 (temporary change, will not affect next loop)
๐น Iteration 2
i = 1 (reset by loop)
print(i) → prints 1
i = 5 (again ignored in next iteration)
๐น Iteration 3
i = 2
print(i) → prints 2
i = 5 (no further effect)
๐น Key Concept
The for loop controls i automatically
Assigning i = 5 inside the loop does not change the loop sequence
๐น Final Output
0
1
2

0 Comments:
Post a Comment