G7_for_loop_WS_02 - MS
G7_for_loop_WS_02 - MS
Grade: 7 Section:
Section A: True/False
1. True - A for loop in Python is used to iterate over a sequence such as a list, tuple, or string.
2. True - The for loop will stop executing once it reaches the end of the sequence.
3. True - In a for loop, the loop variable is updated automatically with the next item in the sequence on
each iteration.
4. True - You can use the break statement to stop the for loop before it has iterated over all the items in
the sequence.
5. False - A for loop can iterate over various data types, including strings, lists, tuples, and not just
numerical ranges.
1. b) It iterates over a sequence of elements - This is the correct description of a for loop.
2. c) It is updated to the next item in the sequence - The loop variable is updated with the next item from
the sequence on each iteration.
3. c) break - The break statement is used to exit the loop before it completes all iterations.
4. c) Skips the current iteration and moves to the next - The continue statement skips the current
iteration and moves to the next one.
5. c) for x in range(1, 6): - This is the correct syntax for a for loop in Python.
Section D: Short Answer Questions
1. Explain how a for loop works in Python and provide an example of iterating over a list of numbers.
A for loop in Python is used to iterate over a sequence of elements, such as a list, string, or range. On
each iteration, the loop variable is assigned the next value from the sequence, and the code block inside
the loop is executed. Example:
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
2. Describe a situation where you might use the break statement in a for loop. Provide an example.
You might use the break statement in a for loop when you want to exit the loop early, based on a
certain condition. For instance, if you are searching for a specific item in a list, you can stop the loop once
you find it. Example:
numbers = [1, 2, 3, 4, 5]
for num in numbers:
if num == 3:
break
print(num)