Related Articles

Related Articles

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output:

Result is 200

My Personal Notes arrow_drop_up
Recommended Articles
Page :