if keyword – Conditional evaluation in Julia
Last Updated :
22 Apr, 2020
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...