Loops will continually run a piece of code as long as the condition it is given is true. Same with conditional statements (if,elif,else), the condition uses acomparison operator.
There are 2 types of loops we will learn. For and while loops
For loops are used when you know how many times you want to repeat the loop
While loops are used when you don't know how many times you want to repeat the loop
For loops use a loop counter that increases to reach a determined number. Once the number is reached the loop stops.
Using i as a loop counter is a convention in programming
When creating multiple for loops it is important to use different loop counters because it is easy to get them mixed up and bugs may occur.
It can be confusing when there are multiple nested loops.
For loops can be declared like this:
For i in range:
{code}
While loops can be declared like this:
While {condition}:
{code}
It is possible to put a loop inside another in coding and is common practice when you are making a more complex program.
Example
for i in range(5):
print('This is the outer loop’,i)
for j in range(3):
print('This is the inner loop’,j)