×
☰ Menu

if-else Statement

 

This statement is used to carry out one of two sets of statements either within if statement or in else statement. When the logical expression is true, the if statement is executes, if statement is false then else statement will execute.

 

Syntax of if…else is :

if(expression)
   {
   statement1;
   statement2;
   }
 else
   {
   statement3;
   statement4;
   }
next_statement;

 

Explanation:

If the expression is True then Statement1 and Statement2 are executed

Otherwise, Statement3 and Statement4 are executed.