Tuesday, September 15, 2020

Nested if-else statement

Nested if-else statement :

When a series of decisions are involved we may have to use more than if statement in nested form as follows :


if  ( test -condition-1)

{

      if ( test-cndition-2)

       {

                  statement - 1

       }

       else

       {

                   statement - 2

       }

}

else

{

                  statement - 3

}

statement - x


The logic of execution is if the condition - 1 is false then the statement - 3 is executed otherwise it continues to perform the condition - 2. if the condition - 2 is true, the statement - 1 is executed otherwise statement statement - 2 is executed. it is shown in following flowchart 

Consider the following example

if ( a>b)

{

     if (a>c)

     {

      printf("%d",a);

      {

      else

       printf("%d",c);

       }

}

else

{

       if(b>c)

       {

       printf("%d",b);

       }

      else

       {

     printf("%d,c");

       }

}

In above exemple, greater number from  a, b and c will be displayed.




2 comments:

Object Paradigm Oriented Programming in C++ / object oriented programming / History of C++/ paradiagram in c++/C devolop, Operating System, Unix operating system, Assembly language, popular in world, Programming language.

  Object Paradigm Oriented Programming  Two programmers, Brian Kernighan and Dennis Ritchie developed a new language called C, in 1972.  C l...