IF Statement

Definition:

  • It is one of the most powerful decision-making conditional statement.
  • IF Statement is always used with condition where condition is checked before executing the body of loop.

Syntax:

The syntax of IF Statement in C-Language

         if(Test Condition)

              {

                 //Statement(S) will execute if test condition is true

               }

How IF Statement Works:

  1. The IF Statement checked the Test Condition which is inside parenthesis ().
  2. If the Test Condition is checked as true then only statement (s) inside the body of IF Statement will execute.
  3. This process will continue until the Test Condition becomes false.
  4. If the Test Condition is checked as false then IF Statement gets terminated.

Illustration of IF Statement:

CASE-1: Test Condition is True

       int a = 4;

       if(a < 8)

            {

                //Statement(s) inside the body of IF Statement loop

             }

              //Statement(s) outside the body of IF Statement loop

CASE-2: Test Condition is False

       int a = 4;

       if(a > 8)

            {

             //Statement(s) inside the body of IF Statement loop

        }

             //Statement(s) outside the body of IF Statement loop

Program: Write a C program to illustrate IF Statement

#include<stdio.h>

int main()

{

   int age = 15;  

   if(age>18)

     {

        printf(“Your age is less than 18”);

     }

     Printf(“I am not inside the IF Loop body”);

}

 Output:

I am not inside the IF Loop body

 

Application:

It is mostly used in the case where we need to perform the different operations for the different conditions.