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.
'if'
keyword in Julia is used to evaluate a condition. If the condition is true, the code after the if statement will be executed otherwise it will skip the same statement and will proceed with the further evaluation of the code.
Syntax:
if condition
statement
end
Flowchart:
Example:
function check_if(x)
if x > 10
println(x, " is greater than 10" )
end
println( "This is not in if" )
end
check_if( 15 )
|
Output:
15 is greater than 10
This is not in if
if
keyword can also be used with the else
keyword to execute another statement in case the if condition results to be false.
Example:
function check_if(x)
if x > 10
println(x, " is greater than 10" )
else
println(x, " is smaller than 10" )
end
println( "This is not in if" )
end
check_if( 15 )
|
Output:
5 is smaller than 10
This is not in if
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