---
title: "Arithmetic versus logical IF"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-arithmetic-vs-logical-if"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-arithmetic-vs-logical-if
site: BCT Engineering
---

# Arithmetic versus logical IF

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2068 Shrawan, 2 marks; 2071 Chaitra, 7 marks; 2070 Chaitra, 4 marks (asked 3 times)
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-arithmetic-vs-logical-if
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

Compare arithmetic and logical if statements in FORTRAN with suitable example.

## Short answer

Arithmetic IF uses sign of an expression to branch to three labels (negative, zero, positive). Logical IF executes one statement when a logical condition (.GE., .LT., etc.) is true. Arithmetic IF is obsolescent, needs labels; logical IF is modeern, no label.

## Answer

#### Arithmetic IF
It is a three-way branch controlled by the sign of an arithmetic expression.

Syntax: `IF (expression) label1, label2, label3`

Control goes to `label1` if the value is negative, `label2` if zero, `label3` if positive.

```fortran
      READ *, X
      IF (X) 10, 20, 30
   10 PRINT *, 'NEGATIVE'
      GO TO 40
   20 PRINT *, 'ZERO'
      GO TO 40
   30 PRINT *, 'POSITIVE'
   40 STOP
      END
```

#### Logical IF
It executes one statement only when a logical (true/false) condition holds.

Syntax: `IF (logical expression) statement`

The logical expression uses relational operators (`.LT. .LE. .EQ. .NE. .GT. .GE.`) and logical operators (`.AND. .OR. .NOT.`).

```fortran
      READ *, X
      IF (X .LT. 0.0) PRINT *, 'NEGATIVE'
      IF (X .GE. 0.0) PRINT *, 'NOT NEGATIVE'
```
The statement cannot be another logical IF or a DO. For more than one statement the block form `IF (cond) THEN ... ELSE ... END IF` is used.

#### Comparison

| Basis | Arithmetic IF | Logical IF |
|---|---|---|
| Expression | Arithmetic (number) | Logical (true/false) |
| Branches | Three (negative, zero, positive) | One statement, executed if true |
| Needs labels | Yes, three | No |
| Style | Old, hard to read (GOTO-like) | Clear and modern |
| Marked obsolescent | Yes (deleted in newer standards) | No |

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. In IF (X) 10, 20, 30, where does control go if X is zero?
   A. Label 10
   B. Label 30
   C. Label 20
   D. The next statement
   Answer: C. Label 1 is for negative, label 2 for zero, label 3 for positive values. (Key point: Arithmetic IF branching)

2. What does a logical IF execute?
   A. One statement only if the logical expression is true
   B. One of three labels by sign
   C. A whole block always
   D. The statement before the IF
   Answer: A. Logical IF has form IF (logical expression) statement; the single statement runs only if the condition is true. (Key point: Logical IF)

3. What kind of expression controls each IF?
   A. Both use logical expressions
   B. Arithmetic IF uses an arithmetic (numerical) expression; logical IF uses a true/false expression
   C. Both use character expressions
   D. Arithmetic IF uses logical, logical IF uses arithmetic
   Answer: B. The arithmetic IF looks at the sign of a number; the logical IF tests a condition such as X .LT. 0.0. (Key point: Expression type)

4. Which statement is correct about labels?
   A. Logical IF needs three labels
   B. Arithmetic IF needs no labels
   C. Arithmetic IF needs three labels and is considered obsolescent; logical IF needs none
   D. Both need exactly one label
   Answer: C. Arithmetic IF needs three labels and is old, GOTO-like style; logical IF needs no labels. (Key point: Labels and style)

## Related in Computer Programming

- [Compare switch and if-else-if ladder](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswitch-vs-ifelse-ladder) — Computer Programming, chapter 5, asked 2×
- [High level languages; C versus FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Ahll-types-c-vs-fortran) — Computer Programming, chapter 1
- [Formatted and unformatted I/O in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-formatted-unformatted-io) — Computer Programming, chapter 11
- [Quadratic equation roots in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-quadratic-roots) — Computer Programming, chapter 11, asked 2×
- [Palindrome check in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-palindrome) — Computer Programming, chapter 11
- [DO versus implied DO loop](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-do-vs-implied-do) — Computer Programming, chapter 11, asked 3×

## Related in other subjects

- [Physical vs logical clocks; Lamport](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alamport-physical-compare) — Distributed System, chapter 5
- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [Pressure rise: rigid versus elastic pipe](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Arigid-vs-elastic-pipe-pressure-rise-5km) — Hydraulics, chapter 4
