Home TechnologyComputers Subscribe to RSS

Can You Explain Nested If-else With Examples?

Answer Question

1 Answer - Sort by: Date | Rating

    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

    0 0

    Pavanhari 

    answered 1 year ago

      More

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International