Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

C – The if statement (if without else statement)

It is possible to use if statement without the else statement.

Syntax

if(condition)
{
    // group of
    // programming
    // statements
}

If the condition inside parentheses is true, if-block is executed. After execution of if-block, program control executes statements after it.

If the condition inside the parenthesis is false, if-block is skipped, and statements after it are executed.

Flow chart of if control statement

C Programming Language if statement Flowchart

Working

C Programming Language if statement Working

Example No 1

 #include<stdio.h>
 int main()
 {
     int i;
     i=5;
     if(i<10)
     {
         printf("Inside if block");
     }
     printf("\n After if block");
     return 0;
 }

Output

Inside if block
After if block

In the above-executed program, the value of i is less than 10. Therefore condition becomes true, and program control enters into if-block and executes the statement inside it.

Example No 2

 #include<stdio.h>
 int main()
 {
     int i;
     i=15;
     if(i<10)
     {
         printf("Inside if block");
     }
     printf("\n After if block");
     return 0;
 }

Output

After if block

In the above program value of i is greater than 10. Therefore condition becomes false and program control skips if-block and executes the statement after it.

 

 

Leave a reply