Intermediate Julia
Anthony Markham
Quantitative Developer
range
is an object, with its own data type.my_range = 1:10 # start:stop
range
will not reveal the sequence of values stored within the object!my_range = 1:10
println(my_range)
1:10
my_range = 0:10:50 # start:step:stop
step
value determines what the next value in the range will be.start
value of onestep
value of 10end
value of 50my_range = 1:10:50
println(my_range)
1:10:50
for
loop can accomplish this, just as we did with a vectormy_range = 0:10:50
for value in my_range
println(value)
end
0
10
20
30
40
50
start
, step
, and stop
can be used to get the corresponding values for a range.my_range = 0:10:50
println(my_range[2])
10
start
, step
, and stop
can be used to get the corresponding values for a range.println(my_range.start)
println(my_range.step)
println(my_range.stop)
0
10
50
while
loop requires accessing each individual range element.[]
notation to access each element, just like vectors.i = 1
as Julia starts indexing at 1, not 0!i = 1
while i <= length(my_range)
println(my_range[i])
i = i + 1
end
...
used to unpack an iterable.my_range = 0:10:50
println([my_range...])
[0, 10, 20, 30, 40, 50]
Intermediate Julia