Understanding the range(1, 10, 3)
This range() generates numbers starting at 1, ending before 10, and increasing by 3 each time.
The values it produces are:
Loop Iteration Breakdown
🔹 First Iteration:
-
i = 1
print(i) → prints 1
i == 4? → ❌ No, so it continues.
🔹 Second Iteration:
-
i = 4
print(i) → prints 4
i == 4? → ✅ Yes, so break is triggered.
✅ Loop stops immediately, so 7 is never printed.
Final Output:
Purpose of break:
The break statement is used to exit the loop early if a condition is met—in this case, when i == 4.


0 Comments:
Post a Comment