For Loops - Test

1. What is a `for` loop used for in Python?

A) Iterating over a sequence (such as a list, tuple, or string)
B) Defining a new function
C) Creating an infinite loop

2. What is the output of the following code?

for i in range(3):     print(i)
A) 1 2 3
B) 0 1 2
C) 0 1 2 3

3. What is the syntax for a `for` loop that iterates over a list?

A) for i in list
B) for i to list
C) while i in list

4. What does the `range()` function return in Python?

A) A sequence of numbers
B) A list of strings
C) A single integer

5. Which loop is better for iterating over a collection?

A) `for` loop
B) `while` loop
C) Both are equally good

6. What is the output of the following code?

list = [10, 20, 30] for i in list:     print(i, end=" ")
A) 10 20 30
B) 30 20 10
C) 10, 20, 30

7. How do you exit a `for` loop prematurely?

A) `continue`
B) `break`
C) `return`

8. What will the following code print?

for i in range(3):     if i == 2:         break     print(i)
A) 0 1
B) 0 1 2
C) 2