LF Fortran 95

WHERE Statement

Description

The WHERE statement masks the assignment of values in array assignment statements. The WHERE statement can begin a WHERE construct that contains zero or more assignment statements, or can itself contain an assignment statement.

Syntax

WHERE (mask-expr) [assignment-stmt]
Where:

mask-expr is a LOGICAL expression.

assignment-stmt is an assignment statement.

Remarks

If the WHERE statement contains no assignment-stmt, it specifies the beginning of a WHERE construct.

The variable on the left-hand side of assignment-stmt must have the same shape as mask-expr.

When assignment-stmt is executed, the right-hand side of the assignment is evaluated for all elements where mask-expr is true and the result assigned to the corresponding elements of the left-hand side.

If a non-elemental function reference occurs in the right-hand side of assignment-stmt, the function is evaluated without any masked control by the mask-expr.

mask-expr is evaluated at the beginning of the masked array assignment and the result value governs the masking of assignments in the WHERE statement or construct. Subsequent changes to entities in mask-expr have no effect on the masking.

assignment-stmt must not be a defined assignment.

Example

! a, b, and c are arrays where (a>b) a=-1 ! where statement where (b>c) ! begin where construct b=-1 elsewhere b=1 end where