Home » Blog » if…else Statement In C

if…else Statement In C

Decision making with if statement may be implemented in different forms depending on the complexity of conditions to be tested.The different forms are,

  1. Simple if statement
  2. if….else statement
  3. Nested if….else statement
  4. Using else if statement

Syntax

if(expression)
{
	//Inside if Statement Are Executed
}
else
{
	//Inside else Statement Are Executed
}	
	//Outside if...else block Statement Are Executed

Here, if the expression is true then if block statements are executed and after it directly outside if…else block statements are executed, otherwise else block statements are executed and after it directly outside if…else block statements are executed. It means if expression is false then else block statements are executed.

Example is below ::

#include <stdio.h>
#include<conio.h>

void main()
{
    int x,y;
	
    clrscr();
	
    x = 15;
    y = 13;
	
    if (x > y )
    {
        printf("x is greater than y");
    }
    else
    {
        printf("y is greater than x");
    }
    getch();
}

OutPut

x is greater than y

It’s Done. Keep It Up Guys…

Leave a Reply

Your email address will not be published.