Step-by-step execution
-
lst = [10, 20, 30]
A list with three elements is created. -
for i in lst:
The loop iterates over each element in the list one by one.
▶️ Iteration 1
-
i = 10
-
Check: if i == 20 → False
-
So print(i) runs → prints 10
▶️ Iteration 2
-
i = 20
-
Check: if i == 20 → True
break executes → the loop stops immediately
print(i) is not executed for 20
▶️ Iteration 3
-
Never runs, because the loop already stopped at break.
✅ Final Output
10Key Concepts
| Keyword | Meaning |
|---|---|
| for | Loops through each element in a list |
| if | Checks a condition |
| break | Stops the loop immediately |
| print(i) | Prints the current value |
Summary
-
The loop starts printing values from the list.
-
When it encounters 20, break stops the loop.
-
So only 10 is printed.
๐ Output: 10


0 Comments:
Post a Comment