Julia voor gevorderden
Anthony Markham
Quantitative Developer
for-lus, maar soms nuttig.expression zolang de condition waar is.while condition
expression
end
counter = 10
while counter != 0
print(counter, " ")
counter = counter - 1
end
10 9 8 7 6 5 4 3 2 1
# Eerste iteratie
counter = 10
while counter != 0 # counter = 10 hier, dus dit is waar
print(counter, " ") # print counter, gelijk aan 10
counter = counter - 1 # verlaag counter met 1
end
10
# Tweede iteratie
counter = 10
while counter != 0 # counter is hier nu 9, dus dit is waar
print(counter, " ") # print counter, gelijk aan 9
counter = counter - 1 # verlaag counter met 1
end
10 9
# Derde iteratie
counter = 10
while counter != 0 # counter is hier nu 8, dus dit is waar
print(counter, " ") # print counter, gelijk aan 8
counter = counter - 1 # verlaag counter met 1
end
10 9 8
counter te verlagen?# Tweede iteratie
counter = 10
while counter != 0 # counter is hier nu 9, dus dit is waar
print(counter, " ") # print counter, gelijk aan 9
end
10 10 10 10 10 10 10 10 10
Julia voor gevorderden