The "if-else" Statement

The "if-else" Statement

This is another form of the "if statement". It is used for making two way decisions. In this statement, one condition and two blocks of statements are given. Either one of the two blocks of statements is executed after evaluating a condition.
      The "if-else" statements tests the given relational condition. If the condition is true then the first block of statements is executed. If the condition is false , the first block of statement is ignored and the second block following the else is executed.

The syntax of "if-else"statements is:

Syntax-1
                      if (condition)
                                  statements-1;
                      else
                                  statement-2;


Syntax-2
                     if (condition)
                         {
                              statement-1;
                              statement-2;                         First block
                              statement-m;
                         }
                         else
                         {
                             statement-1;
                             statement-2;                         Second block
                             statement-n;
                          }

if-else flowchart


Creative Commons License
Pakistan How by Tahira Aijaz is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.