The for
LoopΒΆ
- When we drew the square, it was quite tedious. If we were drawing a polygon with 42 sides, it would have been worse.
- A basic building block is repeating some code, over and over again.
Python’s for loop solves this for us. Let’s say we have some friends, and we’d like to send them each an email inviting them to our party. We don’t quite know how to send email yet, so for the moment we’ll just print a message for each friend:
the loop body is executed here 7 times, and each time f
will refer to a different friend.