Header Ads Widget

Responsive Advertisement

If Statement with Syntax and Examples in C++

Conditional statements help you to make a decision based on certain conditions . These conditions are specified by a set of conditional statements having boolean expressions which are evaluated to a boolean values true or false . 
There are following types of conditional statements in C++:
  • if statement
  • if - else statement
  • nested if-else statement
  • if -else if ladder 
  • switch statement

1. If statement - The statements inside the body of “if” only execute if the given condition returns true. If the condition returns false then the statements inside “if” is not executed.

Syntax :

if (condition)
   // Body of the loop.
   // These statements will only execute if the condition is true.
}


Flow Diagram of if statement

     


Example of if statement in C++


#include <iostream.h>
#include<conio.h>
int main()
{
   int  a=15,b=10;
   if(a<=b)  //if condition statement
    {
      cout<<"Value of a is less than or equal to b."; //display output
    }
  getch();
}

OUTPUT:
Value of a is less than or equal to b.

Post a Comment

0 Comments