November 2017
Beginner
316 pages
6h 40m
English
A return statement terminates the execution of a function and returns control to the calling function. A function in Julia may or may not use the return statement explicitly to return a value. This may be a little different for people coming from other languages, such as Python, but will become relatively easier to follow later.
In the absence of the return statement, the last expression is evaluated and returned. For instance, the underlying pieces of code are equal in terms of the value they return:
# function returns the value computed in the last statementjulia> function add_without_return(x,y) x+y endadd_without_return (generic function with 1 method)julia> add_without_return(20,30)50# function with return statement ...
Read now
Unlock full access