Loop Range:
This means i will go through the numbers:
1, 2, 3, 4, 5
✅ Now, check each value of i:
➤ i = 1
1 % 2 == 0 → ❌ False → does not continue
i == 5 → ❌ False → does not break
✅ print(1, end=" ") → prints 1
➤ i = 2
2 % 2 == 0 → ✅ True → continue (skips the rest of loop)
❌ Nothing is printed.
➤ i = 3
3 % 2 == 0 → ❌ False
i == 5 → ❌ False
✅ print(3, end=" ") → prints 3
➤ i = 4
4 % 2 == 0 → ✅ True → continue
❌ Nothing is printed.
➤ i = 5
5 % 2 == 0 → ❌ False
i == 5 → ✅ True → break
Loop stops before printing 5
✅ Final Output:
Summary:
-
Skips even numbers using continue
-
Stops the loop when i is 5 using break
-
Only odd numbers less than 5 get printed


0 Comments:
Post a Comment