LF Fortran 95

FORALL Statement


The FORALL statement controls execution of an assignment or pointer assignment statement with selection by sets of index values and an optional mask expression.


FORALL ( forall-triplets [, mask] ) forall-assignment-stmt

forall-triplets is a comma-separated list of

index-name=subscript : subscript [: stride]

index-name is a named scalar variable of type INTEGER.

subscript is a scalar INTEGER variable, which is an array index

stride is a scalar INTEGER variable, which is the array stride

mask is a scalar expression of type LOGICAL.

forall-assignment-stmt is an assignment statement

or a pointer assignment statement


Execution of a FORALL construct causes the set of values for index-name to be determined, and mask to be evaluated.

Values for index-name are determined by taking the starting subscript, and incrementing it by the stride until a value falls outside the range subscript : subscript.

mask is evaluated for each combination of index-name values, and assignments in the forall-body are made for those combinations of index-names for which mask evaluates to true.

subscript may not refer to an index-name in the same forall-triplets list.

stride may not make reference to an index-name in the same forall-triplets list.

Any procedure referenced in mask or in forall-assignment-stmt must be a PURE Procedure.

If mask is not present it is as if it were present with the value true.

The set of values for index-name may be determined in any order.

The value of an index-name cannot be altered within the forall-assignment-stmt.


integer :: a(3,3)=(/1,2,3,4,5,6,7,8,9/),i,j forall(i=1:3,j=1:3, j > i) a(i,j)=a(j,i) ! assigns the transpose of the lower triangle of array a write(*,'(3(1x,f10.6))') a

See Also

PURE Procedure