(l is optional) : IF (...) CYCLE : IF (...) EXIT outer : END DO inner END DO outer where we note that loops may be optionally named so that any EXIT or CYCLE statement may specify which loop is meant. Many, but not all, simple loops can be replaced by array expressions and assignments, or by new intrinsic functions. For instance tot = 0. DO i = m, n tot = tot + a(i) END DO becomes simply tot = SUM( a(m:n) ) Program units and procedures Definitions In order to discuss this topic we need some definitions. In logical terms, an executable program consists of one main program and zero or more subprograms (or procedures) - these do something. Subprograms are either functions or subroutines, which are either external, internal or module subroutines. (External subroutines are what we knew from FORTRAN 77.) From an organizational point of view, however, a complete program consists of program units. These are either main programs, external subprograms or modules and can be separately compiled. An example of a main (and complete) program is PROGRAM test PRINT *, 'Hello world!' END PROGRAM test An example of a main program and an external subprogram, forming an executable program, is PROGRAM test CALL print_message END PROGRAM test SUBROUTINE print_message PRINT *, 'Hello world!' END SUBROUTINE print_message The form of a function is FUNCTION name(arg1, arg2) ! zero or more arguments : name = ... : END FUNCTION name The form of reference of a function is x = name(a, b) Internal procedures An internal subprogram is one contained in another (at a maximum of one level of nesting) and provides a replacement for the statement function: SUBROUTINE outer REAL x, y : CONTAINS SUBROUTINE inner REAL y y = x + 1. : END SUBROUTINE inner ! SUBROUTINE mandatory END SUBROUTINE outer We say that outer is the host of inner, and that inner obtains access to entities in outer by host association (e.g. to x), whereas y is a local variable to inner. The scope of a named entity is a scoping unit, here outer less inner, and inner. The names of program units and external procedures are global, and the names of implied-DO variables have a scope of the statement that contains them. Modules Modules are used to package global data (replaces COMMON and BLOCK DATA from Fortran 77); type definitions (themselves a