Can You Explain Nested If-else With Examples?

1

1 Answers

pavan katam Profile
pavan katam answered
SYNTAX for nested if:
IF (logical-expression) THEN
   statements
    IF (logical-expression) THEN
  statements
    ELSE
  statements
    END IF
    statements
ELSE
    statements
    IF (logical-expression) THEN
  statements
    END IF
    statements
END IF

typical example can be
Suppose we need a program segment to read a number x and display its sign.More precisely, if x is positive,
+ is displayed; if x is negative,  - is displayed; otherwise, a 0 is displayed.
With an IF-THEN-ELSE-END IF statement,we have a two-way decision (i.e., true or false)

for this code will look as
IF (x > 0) THEN
   WRITE(*,*)  '+'
ELSE
   IF (x < 0) THEN
  WRITE(*,*)  '-'
   ELSE
  WRITE(*,*)  '0'
   END IF
END IF

Answer Question

Anonymous