Open In App

Julia return keyword

Last Updated : 22 Apr, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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:




# Julia program to illustrate
# the use of 'return' keyword
  
# Function definition
function add(x, y)
      
    # Return statement
    return x + y
end
  
# Function call
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:




# Julia program to illustrate
# the use of 'return' keyword
  
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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads