Julia LanguageConditionals


Syntax

  • if cond; body; end
  • if cond; body; else; body; end
  • if cond; body; elseif cond; body; else; end
  • if cond; body; elseif cond; body; end
  • cond ? iftrue : iffalse
  • cond && iftrue
  • cond || iffalse
  • ifelse(cond, iftrue, iffalse)

Remarks

All conditional operators and functions involve using boolean conditions (true or false). In Julia, the type of booleans is Bool. Unlike some other languages, other kinds of numbers (like 1 or 0), strings, arrays, and so forth cannot be used directly in conditionals.

Typically, one uses either predicate functions (functions that return a Bool) or comparison operators in the condition of a conditional operator or function.