Loops Questions and Answers
Practice ModeShowing 10 of 25 questions
Q1
Which loop in Python is used to iterate over a sequence of elements?
Answer: Option B
Explanation: The for loop in Python is specifically designed to iterate over sequences like lists, tuples, strings, and other iterable objects.
Q2
What is the output of: for i in range(3): print(i)
Answer: Option A
Explanation: range(3) generates numbers 0, 1, 2. The loop prints each number on separate lines.
Q3
Which keyword is used to exit a loop prematurely in Python?
Answer: Option C
Explanation: The break statement immediately terminates the loop and continues with the next statement after the loop.
Q4
What does the continue statement do in a Python loop?
Answer: Option B
Explanation: The continue statement skips the current iteration and moves to the next iteration of the loop.
Q5
How many times will this loop execute: while False: print("Hello")
Answer: Option A
Explanation: Since the condition is False from the beginning, the loop body never executes.
Q6
What is the output of: for i in range(1, 5, 2): print(i)
Answer: Option A
Explanation: range(1, 5, 2) starts at 1, ends before 5, with step 2, producing 1 and 3.
Q7
Which loop is guaranteed to execute at least once in Python?
Answer: Option D
Explanation: Python does not have a built-in do-while loop. Both for and while may execute zero times depending on conditions.
Q8
What does the else clause with a for loop do in Python?
Answer: Option B
Explanation: The else clause in a for loop executes only if the loop completes normally without encountering a break statement.
Q9
How to create an infinite loop in Python?
Answer: Option D
Explanation: while True creates an infinite loop because the condition is always true.
Q10
What is the output of: for char in "Python": print(char, end=" ")
Answer: Option A
Explanation: The loop iterates over each character in the string "Python" and prints them with spaces.