Julia return keyword
Last Updated :
22 Apr, 2020
Keywords in Julia are used to convey a specific pre-defined meaning to the compiles. These words are reserved words and can not be used as variable names.
'return'
keyword in Julia is used to return the last computed value to the caller function. This keyword will cause the enclosing function to exit once the value is returned.
Syntax:
function function_name
return expression
end
Example:
function add(x, y)
return x + y
end
Result = add( 10 , 20 )
println( "Result is " , Result)
|
Output:
Result is 30
return
keyword will make the function to exit immediately and the expressions after the return statement will not be executed.
Example:
function prod(x, y)
return x * y
println( "This will not be executed" )
end
Result = prod( 10 , 20 )
println( "Result is " , Result)
|
Output:
Result is 200
Share your thoughts in the comments
Please Login to comment...