Explanation:
Initialization
s = 0
Creates a variable s and initializes it with 0.
This variable will store the running sum.
Loop Start
for i in range(1, 6):
Loop runs with values of i from 1 to 5.
So the loop will run for:
i = 1, 2, 3, 4, 5
Condition to Skip i = 3
if i == 3:
Checks if the current value of i is 3.
continue
If i is 3, the loop skips the remaining code and moves to the next iteration.
So when i = 3, no addition and no print happen.
Add i to s
s += i
Adds current i value to s.
Condition to Skip if Sum Exceeds 6
if s > 6:
Checks if the current sum s is greater than 6.
continue
If s > 6, printing is skipped.
Printing the Sum
print(s)
Prints the value of s only if it passed both conditions.
Iteration-Wise Execution
1 1 No 1 No 1
2 2 No 3 No 3
3 3 Yes → skipped — — —
4 4 No 7 Yes → skipped —
5 5 No 12 Yes → skipped —
Final Output
1
3
.png)

0 Comments:
Post a Comment