The FORALL construct controls execution of a block of assignment and pointer assignment statements. Execution in the block is selected by sets of index values and an optional mask expression.

## Syntax

[construct-name:]FORALL (forall-triplets [,mask])[forall-body]END FORALL[construct-name]Where:

construct-nameis an optional name for the FORALL construct.

forall-tripletsis a comma-separated list of

index-name=subscript:subscript [:stride]

index-nameis a named scalar variable of type INTEGER.

subscriptis a scalar INTEGER variable, which is an array index

strideis a scalar INTEGER variable, which is the array stride

maskis a scalar expression of type LOGICAL.

forall-bodyis zero or moreassignment or pointer assignment statements, WHERE statements or constructs, or FORALL statements or constructs.

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-name*s
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.

If the FORALL construct has a *construct-name*, the same *construct-name*
must appear at the beginning and end of the construct.

Any procedure referenced in *mask* or in *forall-body* 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-body.

## Example

real :: a(3,3) integer :: i,j forall(i=1:3,j=1:3:2) ! selection by index values a(i,j)=real(i+j) end forall write(*,'(3(1x,f10.6))') a ! row 2 is all zeros forall(i=1:3, j=1:3,a(i,j) == 0.) ! selection by index ! values and scalar mask a(i,j)=i*j ! this assignment is only done for ! elements of a that equal zero end forall write(*,'(3(1x,f10.6))') a