Subroutines

A simple SUBROUTINE takes the form:

SUBROUTINE name(list of arguments)
argument types
declaration of local variables
body of subroutine

END [SUBROUTINE [name] ]

A subroutine is called by using a CALL statement. For example:

PROGRAM Prog4
 INTEGER a
 CALL sub(2,a)
CONTAINS
 SUBROUTINE sub(m,n)
 INTEGER m,n
 n=m+1
 END SUBROUTINE sub
END PROGRAM Prog4

If flow control statements and/or constructs are used within the body of the subroutine then a RETURN statement can be used to exit from the subroutine. The END statement implies RETURN.

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited