Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Julia: return values from function


‘return’ statement is used to return a value from Function (or) return immediately from a function.

julia> function process_data(a)
if(a==10)
print("Returning immediately")
return
end
print("Doubling a")
return 2a
end
process_data (generic function with 1 method)

julia> process_data(10)
Returning immediately
julia>

julia> process_data(20)
Doubling a40

julia> process_data(200)
Doubling a400

Note
If you don’t return a value from function, by default the value of the last expression is returned.

Return multiple values

You can return multiple values from a function.

julia> function swap(a,b)
return b,a
end
swap (generic function with 1 method)

julia> a=10;b=20;

julia> a,b=swap(a,b)
(20,10)

julia> a
20

julia> b
10





Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Julia: return values from function

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×