Loops
In this lesson, we will learn about for and while loops in Python.
We'll cover the following...
A loop is a control structure that is used to repeatedly execute a set of instructions. They solve the problem of having to write the same set of instructions over and over again.
There are two types of loops that we can use in Python:
for
loopwhile
loop
For loops #
In a for loop, we need to define three main things:
- The name of the iterator
- The sequence to be traversed
- The set of operations to be performed
for iterator in sequence:
operations to be performed
The in
keyword specifies that the iterator will go through the values in the sequence or data structure. ...