If Else Statement Sample

An If Else Statement is one of the existing programming selection controls available. This simple tutorial is to explain on the concept of If Else statement sample used in various programming languages. An If Else statement is used to control the execution of parts of a code depending on certain available conditions.

IF Else Statement Syntax

Below is the syntax of an If Else statement sample

If(Condition)

{

Code to be executed

}

Else

{

Code to be executed

}

The “If” statement tests the first condition and when the condition is satisfied (is true), the code within the curly braces is executed. If the condition is not met, then the program proceeds to the else and executes the code within the else curly braces. This is further elaborated as you can observe in the If Else Statement Flow Chart below.

If Else Statement Flow Chart

 

Applications of If Else Statement Sample

If Else Statement Real Life Application

In this section we will see how the If Else Statement Sample is applied in real life situation using a simple procedure. Take for instance when you move to a closed door, you try it to find if it is locked, if it is locked you have to find a key to open it, else if it is not locked, open and go in.

Demonstration

If(Door is open)

{

Go in

}

Else

{

Find key to open

}

If Else Statement Sample in C programming Language

#include <stdio.h>

#include <stdlib.h>

 

int main()

{

int x;

printf(“Enter a number to find if it is Even or Odd:”);

scanf (“%d”,&x);

if((x%2) == 0)

{

printf(“\nThe number %d Even number”,x);

}

else

{

printf(“\nThe number %d is Odd number”,x);

}

return 0;

}

Click PLACE ORDER to get a SIMILAR paper on this topic done for you