Intel® Fortran Compiler 16.0 User and Reference Guide

EXIT Statement

Statement: Terminates execution of a DO loop or a BLOCK construct.

EXIT [name]

name

(Optional) Is the name of the DO loop or BLOCK construct.

Description

The EXIT statement causes execution of a DO loop or a named BLOCK construct to be terminated.

If name is specified, the EXIT statement must be within the range of that named construct. Otherwise, the EXIT statement must be within a DO loop and it exits the innermost DO within which it appears.

If a DO loop is terminated, any inner DO loops are also terminated and the DO control variables retain their last value. If a non-DO construct is terminated, any DO loops inside that construct are also terminated.

An EXIT statement must not appear within a CRITICAL or DO CONCURRENT construct if it belongs to that construct or an outer construct.

Example

The following example shows an EXIT statement:

LOOP_A : DO I = 1, 15
  N = N + 1
  IF (N > I) EXIT LOOP_A
END DO LOOP_A

The following shows another example:

    INTEGER numpoints, point
    REAL datarray(1000), sum
    sum = 0.0
    DO point = 1, 1000
      sum = sum + datarray(point)
      IF (datarray(point+1) .EQ. 0.0) EXIT
    END DO

The following shows another example:

DO I=1,N
   MyBlock:  BLOCK
     REAL :: T
    T = A(I) + B(I)
    IF (T == 0.0) EXIT MyBlock
    C(I) = T + SQRT(T)
    END BLOCK
END DO

See Also