Lesson contents

Check after the first turn

Do the work once, then decide whether another turn is needed. The first value is always printed.

Simple example

Print, then test.

Start1 → 3
Result1 2 3
lesson.jl
function main()
    number = 1
    while true
        println(number)
        number += 1
        number > 3 && break
    end
end

main()
Output
1
2
3
Advertisements

Everyday examples

Print the first waiting ticket even if nobody else is in line. The last ticket today is 41.

StartFirst 41 · last 41
Result41
lesson.jl
function main()
    ticket = 41
    while true
        println(ticket)
        ticket += 1
        ticket > 41 && break
    end
end

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