Lesson contents

Fixed values

Give a value a name and reuse it wherever the same amount is needed. In Julia this example uses a local binding inside a function.

Simple example

Use the same factor twice.

Start3 × 2
Result6
lesson.jl
function main()
    factor = 3
    println(factor * 2)
end

main()
Output
6
Advertisements

Everyday examples

Each bus ticket costs 4 coins. What do three tickets cost?

Start4 × 3
Result12
lesson.jl
function main()
    fare = 4
    println(fare * 3)
end

main()
Output
12
Run the example
Terminal
julia lesson.jl
Official documentation