May 2019
Beginner to intermediate
466 pages
10h 44m
English
All, except maybe the most basic, programs must be able to evaluate variables and execute different logical branches depending on their current values. Conditional evaluation allows portions of the code to be executed (or not) depending on the value of a Boolean expression. Julia provides the if, elseif, and else statements for writing conditional expressions. They work like this:
julia> x = 5
5 julia> if x < 0
println("x is a negative number")
elseif x > 0
println("x is a positive number greater than 0")
else
println("x is 0")
end
x is a positive number greater than 0
If the condition x < 0 is true, then its underlying block is evaluated. If not, the expression x > 0 is evaluated, ...
Read now
Unlock full access