Does Fortran Use Arithmetic If Statements?

  • Fortran
  • Thread starter gholamghar
  • Start date
  • Tags
    Fortran Type
In summary, the conversation discusses a code from a thesis that uses "If" statements and the difference between using a "=" sign or a "-" sign in the statement. It is explained that in Fortran, the "-" sign is used for an "arithmetic if" statement and is equivalent to using "<", "==", or ">" in an if statement. It is also mentioned that this is an old style in Fortran.
  • #1
gholamghar
27
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
  • #2


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...
 
  • #3


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:)
 

FAQ: Does Fortran Use Arithmetic If Statements?

1. What is the purpose of "Fortran has this type of If"?

"Fortran has this type of If" refers to the conditional statement in the Fortran programming language. It allows the program to make decisions based on the result of a logical expression, helping control the flow of the program.

2. How does the "Fortran has this type of If" statement work?

The "Fortran has this type of If" statement evaluates a logical expression and executes a block of code only if the expression is true. If the expression is false, the code inside the If statement is skipped.

3. Can the "Fortran has this type of If" statement handle multiple conditions?

Yes, the "Fortran has this type of If" statement can handle multiple conditions by using the ELSE IF and ELSE clauses. This allows the program to check for multiple cases and execute different blocks of code accordingly.

4. Are there any other conditional statements in Fortran besides "Fortran has this type of If"?

Yes, Fortran also has the SELECT CASE statement which allows the program to check a variable against a list of values and execute different blocks of code based on the value of the variable.

5. Can the "Fortran has this type of If" statement be nested?

Yes, the "Fortran has this type of If" statement can be nested, meaning an If statement can contain another If statement inside its block of code. This allows for more complex decision-making in the program.

Similar threads

Replies
4
Views
1K
Replies
12
Views
2K
Replies
8
Views
1K
Replies
16
Views
2K
Replies
3
Views
2K
Replies
21
Views
2K
Replies
7
Views
3K
Replies
9
Views
4K
Back
Top