In Python, loops are control flow structures that allow you to repeatedly execute a block of code as long as a certain condition is true or for a specific number of iterations
A for loop is used to iterate through a set of statements for a specefic number of times.
numbers = [1, 2, 3, 4, 5]
for num in numbers:
print(num)
for i in range(5): # Loops from 0 to 4
print(i)
for i in range(10):
if i == 5:
break # Stops the loop when i is 5
print(i)
A while loop is used to iterate through a set of statements while a condition is true
count = 0
while count < 5:
print(count)
count += 1
x = 0
while x < 10:
if x == 5:
break
print(x)
x += 1
while True:
print("This will run forever!")
user_input = ""
while user_input != "exit":
user_input = input("Type 'exit' to stop: ")