For Loops Lesson
For Loops Lesson
1 for x in range(5):
2 print(x) Question .
1 for x in range(5):
2 print(x) The values 0 to 4 will be output on the
screen.
0
1
2
3
4
>>>
Objectives
Objectives L9-12
In this lesson, you will:
● Understand the difference between a for and a while loop.
● Be able to use counter controlled (for) loops.
● Be able to use condition controlled (while) loops.
3
Activity 1
1 for x in range(5):
2 print(x) This is an example of a for loop.
● Letters in a word
● Items in a list
● Numbers in a range
Activity 1
1 for x in range(6):
2 print(x) range() is the sequence that you are going
to iterate through.
1 for x in range(6):
2 print(x) When you call the range function, you can
pass it up to three values:
0,1,2,3,4,5
Activity 1
range(5) Pass one value and it will be used as the end point.
0, 1, 2, 3, 4
range(3,10)
Pass two values and they will be used as the start and
3, 4, 5, 6, 7, 8, 9
end point.
range(1, 11, 2) Pass three values and they will be used as the start,
1, 3, 5, 7, 9 end, and the increment (step).
Activity 2
Questions