- Asked 3/16
- 2068 Shrawan · 2 marks
- 2071 Chaitra · 7 marks
- 2070 Chaitra · 4 marks
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
| 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 |
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Compare switch and if-else-if ladder · Computer Programming, chapter 5 · asked 2×
- High level languages; C versus FORTRAN · Computer Programming, chapter 1
- Formatted and unformatted I/O in FORTRAN · Computer Programming, chapter 11
- Quadratic equation roots in FORTRAN · Computer Programming, chapter 11 · asked 2×
- Palindrome check in FORTRAN · Computer Programming, chapter 11
- DO versus implied DO loop · Computer Programming, chapter 11 · asked 3×
- Physical vs logical clocks; Lamport · Distributed System, chapter 5
- 8085 ALP: compare two tables of 16-bit data · Microprocessor, chapter 2
- Pressure rise: rigid versus elastic pipe · Hydraulics, chapter 4