2

I'm trying to teach myself fortran so I can unravel an old program and repurpose it for our own use. I can't figure out what this statement does:

if(s - fm) 198, 198, 197

s - fm isn't a condition that can be true or false, right?.

And when it passes control to the line marked 198, does it then continue to the end of the program? How does it know when to come back to execute 198 again and then 197?

Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82

2 Answers2

8

This is an "archaic" form of IF:

IF (''arithmeticExpression'') ''firstLineNumber'', ''secondLineNumber'', ''thirdLineNumber''

In the second form, the arithmetic expression is evaluated. If the expression evaluates to a negative number, then execution continues at the first line number. If the expression evaluates to zero, then execution continues at the second line number. Otherwise, execution continues at the third line number.

It's a "three-way goto" depending on the sign of the expression.

In a more traditional C-like language it wood be

/* IF(a) label1, label2, label3 */

if(a > 0)
{
   goto label3;
} else
if(a < 0)
{
   goto label1;
} else
{
   // a == 0
   goto label2;
}

Your case contains two labels 198 which works like

if(s <= fm) { goto lbl198; } else { goto lbl197; }

Ref: wikibooks

Viktor Latypov
  • 14,289
  • 3
  • 40
  • 55
3

This obsolete feature puzzles a lot of people:

FORTRAN compiler warning: obsolete arithmetic IF statement

Fortran strange IF

strange label usage

Community
  • 1
  • 1
M. S. B.
  • 28,968
  • 2
  • 46
  • 73