We all know that the DO loop is more powerful than the FORALL statement in Fortran. That is, you can always substitute a FORALL by a DO, but not vice versa.
What about the WHERE statement and block?
Can I always substitute the IF by a WHERE? Is it always possible to code the conditionals and bifurcations with a WHERE, thus avoiding the IF?
WHERE statements are reserved for arrays assignments and nothing else, e.g.:
INTEGER, DIMENSION(100,100) :: a, b
... define a ...
WHERE(a < 0)
b = 1
ELSEWHERE
b = 0
ENDWHERE
If you tried adding in something, say a WRITE statement, inside the WHERE block, you would see something like the following compiling error (compiler dependent):
Error: Unexpected WRITE statement in WHERE block at (1)
EDIT
Note that nested WHERE blocks are legal:
WHERE(a < 0)
WHERE( ABS(a) > 2)
b = 2
ELSEWHERE
b = 1
ENDWHERE
ELSEWHERE
b = 0
ENDWHERE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With