Loops
Introduction in repeating code
By Rotary Viper Home
Loops can be used to repeat lines of code over and over again.
In python, there are two types of loops. While Loops & Fore Loops.
For loop
End condition:
When all subscriptable values are iterated over.
While loop
End condition:
When set end condition is met when loop finishes.
In for loops:
If you ran the code:
print(tuple(range(5)))
for i in range(5):
    print(i*2)
Python would output:
(0, 1, 2, 3, 4)
0
2
4
6
8
In while loops:
If you ran the code:
n1, n2, count = 0, 1, 0
totalCount = int(input('Num fib numbers: '))
while count != totalCount:
    print(n1)
    newn2 = n1 + n2
    n1 = n2
    n2 = newn2
    count += 1
Python would output:
Num fib numbers: 7
0
1
1
2
3
5
8