Loops
Execute a block of code repeatedly.
Types of loops
for loop:
Iterates over a sequence.while loop:
Executes as long as a condition is True.
For Loop
Syntax
for iterating_variable in iterable_list:
# block of code you want to loop over and over
Example
for i in range(5):
print(i) # Prints 0, 1, 2, 3, 4
While Loop
Syntax
while True:
# block of code you want to loop over and over
Example
while True:
if user_input <= 0:
# prompt again ...