Løkker for og while

Video:

Innhold:

While løkke:

1
2
3
4
5
6
7
a = 1
 
while a <= 4:
    print(a)
    a+=1
     
# Gir ut 1 2 3 4

for løkke 1:

1
2
3
4
for i in range(1, 5):
    print(i)
     
# Gir ut 1 2 3 4

for løkke 2:

1
2
3
4
for i in range(5):
    print(i)
     
# Gir ut 1 2 3 4

Linker