■ For Loop and While Loop Quiz ■
1. A for loop is used when:
A. The number of iterations is unknown
B. The loop must run indefinitely
C. The number of iterations is known beforehand
D. None of the above
Answer: C
2. A while loop continues to execute:
A. A fixed number of times
B. Until the given condition becomes false
C. Only once
D. Forever
Answer: B
3. What will be the output of this code? for i in range(3): print(i)
A. 0 1 2
B. 1 2 3
C. 0 1 2 3
D. Error
Answer: A
4. Which loop may never execute if the condition is false initially?
A. for loop
B. while loop
C. both
D. none
Answer: B
5. What will happen if the condition in a while loop is always true?
A. Loop will run only once
B. It will create an infinite loop
C. It will show syntax error
D. It will skip the loop
Answer: B
6. In Python, the range(1, 5) in a for loop runs from:
A. 1 to 5
B. 0 to 5
C. 1 to 4
D. 0 to 4
Answer: C
7. Which of the following loops requires manual increment or update
of the variable?
A. for loop
B. while loop
C. both
D. none
Answer: B
8. What is the output? i = 1 while i < 3: print(i) i += 1
A. 1 2
B. 1 2 3
C. 0 1 2
D. Infinite loop
Answer: A
9. Which statement can stop a loop in Python before its natural end?
A. stop
B. end
C. break
D. continue
Answer: C
10. Which of the following loops is entry-controlled?
A. for loop only
B. while loop only
C. both
D. none
Answer: C