Julia doc: Conditional Operation
IF
if *condition 1*
*option 1*
elseif *condition 2*
*option 2*
else
*option 3*
end
function FizzBuzz(๐ฅ)
if (๐ฅ % 3 == 0) && (๐ฅ % 5 == 0)
println("Fizz Buzz ๐")
elseif ๐ฅ % 3 == 0
println("$(๐ฅ รท 3) Fizz")
elseif ๐ฅ % 5 == 0
println("$(๐ฅ รท 5) Buzz ๐")
else
println("$๐ฅ")
end
end
FizzBuzz (generic function with 1 method)
if
return a value, so we can assign a value after that.
x = 2
โ = if x > 0
"positive"
else
"negative"
end
โ
Boolean in if
must be true
or false
.
if 1
println("true")
end
# This will error
Ternary operators
Translate to
what_is_larger(x, y) = x > y ? "$x is larger than $y" : "$y is larger than $x"
what_is_larger(1, 2)