Arithmetic `if`

statement allows one to use three branches depending on the result of an arithmetic expression

```
if (arith_expr) label1, label2, label3
```

This `if`

statement transfers control flow to one of the labels in a code. If the result of `arith_expr`

is negative `label1`

is involved, if the result is zero `label2`

is used, and if the result is positive last `label3`

is applied. Arithmetic `if`

requires all three labels but it allows the re-use of labels, therefore this statement can be simplified to a two branch `if`

.

Examples:

```
if (N * N - N / 2) 130, 140, 130
if (X) 100, 110, 120
```

Now this feature is obsolete with the same functionality being offered by the `if`

statement and `if-else`

construct. For example, the fragment

```
if (X) 100, 110, 120
100 print*, "Negative"
goto 200
110 print*, "Zero"
goto 200
120 print*, "Positive"
200 continue
```

may be written as the `if-else`

construct

```
if (X<0) then
print*, "Negative"
else if (X==0) then
print*, "Zero"
else
print*, "Positive"
end if
```

An `if`

statement replacement for

```
if (X) 100, 100, 200
100 print *, "Negative or zero"
200 continue
```

may be

```
if (X<=0) print*, "Negative or zero"
```

This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0

This website is not affiliated with Stack Overflow