Read an item by its position
Pick an item using its position in the list. Here we read the second item every time.
getindex
Simple example
Read the second number.
Start4 · 7 · 9
Result7
function main()
values = [4, 7, 9]
println(values[2])
end
main()
7
Advertisements
Everyday examples
Which ticket is second in the queue?
Start42 · 17 · 23
Result17
function main()
values = [42, 17, 23]
println(values[2])
end
main()
17
Which stop does the bus visit second?
Start8 · 6 · 2
Result6
function main()
values = [8, 6, 2]
println(values[2])
end
main()
6
What was the second thermometer reading?
Start19 · 21 · 20
Result21
function main()
values = [19, 21, 20]
println(values[2])
end
main()
21