I am converting an old code in Fortran which I think is a 77. there a couple of usage of IF in the following way that I can't realize what it does:
IF(x1-x2) 12, 13, 14
12 WRITE(*,*) x1
.
.
.
13 y=...
.
.
14 DO x=x1,x2
IF(x-x2) 33, 34, 40
.
.
.
The code complies and runs fine and it produces the results. Has anyone encountered such a usage of IF?
That's an arithmetic IF
. It branches to the first, second, or third label depending on whether the expression is negative, zero, or positive.
In very old versions of Fortran (or FORTRAN), it was the only form of IF
statement that was available.
It's probably a little odd to see it used in a version as recent as Fortran 77, which had a more modern logical IF
. The feature was declared obsolescent in Fortran 90, but I wouldn't be surprised if more modern Fortran compilers still support it.