Intermediate Julia
Anthony Markham
Quantitative Developer
for
loop, but still useful in some cases.expression
while the condition
is true.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
# First iteration
counter = 10
while counter != 0 # counter = 10 here, so this is true
print(counter, " ") # print counter, equal to 10
counter = counter - 1 # decrease the value of counter by 1
end
10
# Second iteration
counter = 10
while counter != 0 # counter now = 9 here, so this is true
print(counter, " ") # print counter, equal to 9
counter = counter - 1 # decrease the value of counter by 1
end
10 9
# Third iteration
counter = 10
while counter != 0 # counter now = 8 here, so this is true
print(counter, " ") # print counter, equal to 8
counter = counter - 1 # decrease the value of counter by 1
end
10 9 8
counter
variable?# Second iteration
counter = 10
while counter != 0 # counter now = 9 here, so this is true
print(counter, " ") # print counter, equal to 9
end
10 10 10 10 10 10 10 10 10
Intermediate Julia