Skip to main content

Arithmetic versus logical IF

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.

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

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.

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

      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

BasisArithmetic IFLogical IF
ExpressionArithmetic (number)Logical (true/false)
BranchesThree (negative, zero, positive)One statement, executed if true
Needs labelsYes, threeNo
StyleOld, hard to read (GOTO-like)Clear and modern
Marked obsolescentYes (deleted in newer standards)No

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →