0
0
Pythonprogramming~20 mins

While loop execution flow in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
While Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple while loop
What is the output of this code?
Python
i = 0
while i < 3:
    print(i)
    i += 1
A
1
2
3
B
0
1
2
3
C
0
1
2
D
0
1
2
3
4
Attempts:
2 left
💡 Hint
Remember the loop runs while the condition is true, and stops when it becomes false.
Predict Output
intermediate
2:00remaining
While loop with break statement
What is the output of this code?
Python
count = 0
while True:
    print(count)
    count += 1
    if count == 3:
        break
A
0
1
2
B
0
1
2
3
C
1
2
3
D
0
1
2
3
4
Attempts:
2 left
💡 Hint
The break stops the loop when count reaches 3.
Predict Output
advanced
2:00remaining
While loop with else clause
What is the output of this code?
Python
i = 0
while i < 3:
    print(i)
    i += 1
else:
    print('Done')
A
0
1
2
Done
B
0
1
2
CDone
D
0
1
2
3
Done
Attempts:
2 left
💡 Hint
The else block runs after the while loop finishes normally.
Predict Output
advanced
2:00remaining
While loop with continue statement
What is the output of this code?
Python
i = 0
while i < 5:
    i += 1
    if i == 3:
        continue
    print(i)
A
1
2
3
4
5
B
2
3
4
5
C
1
2
5
D
1
2
4
5
Attempts:
2 left
💡 Hint
The continue skips printing when i is 3.
🧠 Conceptual
expert
2:00remaining
Understanding infinite loops
Which option will cause an infinite loop when run?
A
i = 0
while i &lt; 5:
    print(i)
    i += 1
B
i = 0
while i != 5:
    print(i)
C
i = 0
while i &lt; 5:
    print(i)
    i += 2
D
while True:
    print('Hello')
    break
Attempts:
2 left
💡 Hint
Check if the loop variable changes so the condition can become false.