Like any programming language, Julia provides most of the control and conditional expressions.
It does not have support for switching and goto in if the conditional expression
It provides the following features
- if-else if
Julia If the else conditional statement
if-else conditional statements are used to execute statements based on conditional expressions.
if conditional expression //if code block executed else //else code block executed end
conditional expression is
true, if code block executed, else code block executed.
age = 25 if age > 60 println("60") else println("less than 60") end
less than 60
Julia if else if conditional expressions
This is an advanced to basic if-else expression.
It is used to test multiple conditions if and else expressions.
if conditional expression1 //block 1 executed elseif conditional expression2 //block 2 executed else //else code block executed end
conditional expression1 is true, block 1 code executed
conditional expression2 is true, block 2 code executed else block will be executed if both conditions are false.
Here is an example of if-else if conditional expression example
age = 40 if age < 25 println("less than 25") elseif age > 60 println("greater than 60") else println("Between 25 and 60") end
Between 25 and 60