FORALL
Purpose
The FORALL statement performs assignment to groups of subobjects, especially array elements. Unlike the WHERE statement, assignment can be performed on an elemental level rather than on an array level. The FORALL statement also allows pointer assignment.
Syntax
- forall_header
- forall_triplet_spec
- forall_assignment
- is either assignment_statement or pointer_assignment_statement
type_spec- specifies an integer type

- scalar_mask_expr
- is a scalar logical expression
- subscript, stride
- are each scalar integer expressions
Rules
Only pure procedures can be referenced in the mask expression of forall_header and in a forall_assignment (including one referenced by a defined operation, assignment, or finalization).
index_name must be a scalar integer variable. It is also a statement entity; that is, it does not affect and is not affected by other entities in the scoping unit.

- The value range of index_name exceeds the range of the default integer type.
- The IMPLICIT NONE statement is in effect. See Example 2.
You can specify type_spec to declare index_name within the scope of the FORALL statement. If you specify type_spec in forall_header, you can reuse any accessible identifier for index_name.

In forall_triplet_spec_list, neither a subscript nor a stride can contain a reference to any index_name in the forall_triplet_spec_list. Evaluation of any expression in forall_header must not affect evaluation of any other expression in forall_header.
index1 = s1:s2:s3
the
maximum number of index values is determined by: max = INT((s2-s1+s3)/s3)
If
the stride (s3 above) is
not specified, a value of 1 is assumed. If max ≤
0 for any index, forall_assignment is not
executed. For example, index1 = 2:10:3 ! The index values are 2,5,8.
max = INT((10-2+3)/3) = 3.
index2 = 6:2:-1 ! The index values are 6,5,4,3,2.
index2 = 6:2 ! No index values.
If the mask expression is omitted, a value of .TRUE. is assumed.
No atomic object can be assigned to more than once. Assignment to a nonatomic object assigns to all subobjects or associates targets with all subobjects.
Examples
Example 1INTEGER A(1000,1000), B(200)
I=17
FORALL (I=1:1000,J=1:1000,I.NE.J) A(I,J)=A(J,I)
PRINT *, I ! The value 17 is printed because the I
! in the FORALL has statement scope.
FORALL (N=1:200:2) B(N)=B(N+1)
END

IMPLICIT NONE
INTEGER, PARAMETER :: limit=60000
INTEGER(1) :: flag(limit)
flag=0
FORALL (INTEGER(4) :: i=2:limit:2) flag(i)=1
PRINT *, flag(limit)
END




