Step-by-Step Execution
Initialize num
- num = 2 (This sets num to 2 before the loop starts.)
Start the while loop
- The loop runs as long as num < 7.
Loop Iteration Details
- First Iteration:
- num += 2 → num = 2 + 2 = 4
- print(num) → Output: 4
- Second Iteration:
- num += 2 → num = 4 + 2 = 6
- print(num) → Output: 6
- Third Iteration:
- num += 2 → num = 6 + 2 = 8
- print(num) → Output: 8
- First Iteration:
Exit Condition
- Now, num = 8, which is not less than 7, so the loop stops.
0 Comments:
Post a Comment