Does Fortran Use Arithmetic If Statements?

  • Context: Fortran 
  • Thread starter Thread starter gholamghar
  • Start date Start date
  • Tags Tags
    Fortran Type
Click For Summary
SUMMARY

Fortran employs an "arithmetic if" statement, which utilizes a minus sign (-) rather than an equals sign (=) for conditional checks. This old style of coding allows for branching based on the result of arithmetic expressions. Specifically, the statement "If (SPFR - .1) 21, 21, 2" translates to three conditional jumps: if (SPFR - .1 < 0) goto 21, if (SPFR - .1 == 0) goto 21, and if (SPFR - .1 > 0) goto 2. Understanding this syntax is crucial for interpreting legacy Fortran code.

PREREQUISITES
  • Familiarity with Fortran programming language
  • Understanding of control flow statements in programming
  • Knowledge of arithmetic operations and comparisons
  • Experience with legacy codebases
NEXT STEPS
  • Research the history and evolution of Fortran programming language
  • Learn about modern alternatives to arithmetic if statements in Fortran
  • Explore best practices for maintaining and refactoring legacy Fortran code
  • Study the differences between Fortran 77 and later versions regarding control flow
USEFUL FOR

Programmers working with legacy Fortran code, software engineers maintaining scientific computing applications, and educators teaching Fortran syntax and programming concepts.

gholamghar
Messages
23
Reaction score
0
Fortran has this type of "If"?

Hi,
I was reading a code from a thesis, obviously the quality of the scan was not good and I reached to this point in the image below, that the programmer uses "If" statements:

http://i48.tinypic.com/x5z7n.jpg


I am not sure if he uses a "=" sign or a"-" sign for his statement. I mean this is "If (SPFR - .1) 21, 21, 2" or (SPFR = .1) 21, 21, 2"?
do we have such a thing in fortran for an If statement using a minus sign?

Thanks Frotran Masters!
 
Technology news on Phys.org


gholamghar said:
Hi,
I was reading a code from a thesis, obviously the quality of the scan was not good and I reached to this point in the image below, that the programmer uses "If" statements:

http://i48.tinypic.com/x5z7n.jpg


I am not sure if he uses a "=" sign or a"-" sign for his statement. I mean this is "If (SPFR - .1) 21, 21, 2" or (SPFR = .1) 21, 21, 2"?
The symbol is -, not =. This is a very old style in Fortran, and it's called an "arithmetic if" statement.

It's equivalent to these statements:

if (SPFR - .1 < 0) goto 21
if (SPFR - .1 == 0) goto 21
if ((SPFR - .1 > 0) goto 2
gholamghar said:
do we have such a thing in fortran for an If statement using a minus sign?

Thanks Frotran Masters!
That would be Fortran...
 


Mark44 said:
The symbol is -, not =. This is a very old style in Fortran, and it's called an "arithmetic if" statement.

It's equivalent to these statements:

if (SPFR - .1 < 0) goto 21
if (SPFR - .1 == 0) goto 21
if ((SPFR - .1 > 0) goto 2

That would be Fortran...

Thank you so much Mark44, you are awesome! and knowledgeable:)
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 9 ·
Replies
9
Views
5K