November 2017
Beginner
316 pages
6h 40m
English
After taking a closer look at how conditional evaluation works in Julia, let's shift our focus to one more important topic, repeated evaluation.
In Julia, we are provided with two constructs, namely while and for. These two are used for evaluating the code in loops. The following is an example, for both while and for loops:
julia> collection = [1,2,3,4,5,6,7,8,9]
9-element Array{Int64,1}:
1
2
3
4
5
6
7
8
9
julia> while length(collection) > 1
pop!(collection)
println(collection)
end
[1,2,3,4,5,6,7,8]
[1,2,3,4,5,6,7]
[1,2,3,4,5,6]
[1,2,3,4,5]
[1,2,3,4]
[1,2,3]
[1,2]
[1]
In this example, we have an array of integers from 1 to 9. We named it collection, and then we used a while construct to loop over the array of items till ...
Read now
Unlock full access