Løkker – For og while

Video(NTNU):

Innhold:

While løkke:


a = 1

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


for løkke 1:


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


for løkke 2:


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


Linker