Next: Factorial Example
Up: CS101 Lecture 10
Previous: Why Functions?
type FUNCTION function-name (arg1, arg2, ..., argn)
! type above is of the value returned
IMPLICIT NONE !! must put this
[specification part] !! declare all vars (including arg1, ..., argn)
! Local vars can be used inside function
[execution part] !! do whatever calculatoins you need.
! last statement is typically
! function-name = return-value
END FUNCTION function-name
- formal arguments are arg1, ..., argn
- The types and intent must be declared in specification part.
(typically- INTENT(IN) means they receive information from outside
and should not be changed inside the function.)
- Local vars can be used inside the function. not visible outside.
- When control reaches END FUNCTION,
the most recent value stored in the function-name is returned.
- Never use the function name in the right-hand side of an expression.
G. Sivakumar
2000-08-23