0% found this document useful (0 votes)
15 views4 pages

For vs While Loop Quiz Answers

The document contains a quiz focused on for loops and while loops in Python, with multiple-choice questions covering their characteristics and behaviors. Key concepts include when to use each loop type, the output of specific code snippets, and the implications of loop conditions. The correct answers to each question are provided, highlighting important aspects of loop control in programming.

Uploaded by

tripathisun6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

For vs While Loop Quiz Answers

The document contains a quiz focused on for loops and while loops in Python, with multiple-choice questions covering their characteristics and behaviors. Key concepts include when to use each loop type, the output of specific code snippets, and the implications of loop conditions. The correct answers to each question are provided, highlighting important aspects of loop control in programming.

Uploaded by

tripathisun6
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

■ 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

You might also like