Procedures
Functions
Return a Result
A function ... result(out) returns a value. The result clause names the return variable.
Program
Play the program to add tax to a subtotal with a function.
functions.f90
program functions_demo
implicit none
integer :: subtotal, total
subtotal = 25
total = add_tax(subtotal)
print '(I0)', total
contains
function add_tax(price) result(out)
integer, intent(in) :: price
integer :: out
out = price + price / 10
end function add_tax
end program functions_demo
function
`function name(args) result(out)` returns a value.
intent(in)
`intent(in)` marks an argument read-only.
result clause
`result(out)` names the variable that holds the return.