Lektion 7 af 10
Loops
Python har primært for og while. range() laver en sekvens af tal, som ofte bruges i for-loops.
PYTHON
# For loop with range
for i in range(5):
print(i) # 0, 1, 2, 3, 4
# For loop with list
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
# While loop
n = 0
while n < 3:
print(n)
n += 1