Loading...
Quiz: For and While Loop
Practice Python's for and while loops. This quiz covers loop syntax, break, continue, range(), else, and nested loop logic with real-world examples.
1.
What is the primary purpose of a for loop in Python?
2.
What will this code output?
python
3 lines
|25/ 500 tokens
1 2 3vegetables = ["carrot", "potato", "tomato"] for vegetable in vegetables: print(vegetable)
Code Tools
3.
Which keyword is used to exit a loop early?
4.
What does the continue keyword do in a loop?
5.
How many times will this loop run?
python
4 lines
|17/ 500 tokens
1 2 3 4counter = 1 while counter < 4: print(counter) counter += 1
Code Tools