Open In App
Related Articles

else keyword in Julia

Improve Article
Improve
Save Article
Save
Like Article
Like

Keywords in Julia are reserved words that have a specific meaning and operation to the compiler. These keywords can not be used as a variable name, doing the same will stop the execution process and an error will be raised.

‘else’ keyword in Julia is used to execute a block of code when the ‘if’ condition is false. If the condition is true, the code after the if statement will be executed otherwise the body of else statement will be executed.
Syntax:

if condition
    statement
else
    statement
end

Flowchart:
else-keyword-julia

Example:





Output:

5 is smaller than 10
This is not in if

'else' keyword can also be used with 'if' keyword to generate an ‘if-elseif-else’ ladder.

Example:




# Julia program to illustrate
# if-elseif-else ladder 
i = 20
if (i == 10
    println("Value of i is 10"
elseif(i == 15
    println("Value of i is 15"
elseif(i == 20
    println("Value of i is 20"
else
    println("Value of i is not defined"
end 


Output:

Value of i is 20
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 22 Apr, 2020
Like Article
Save Article
Previous
Next
Similar Reads