C++ if else statement

C++ if else statement: The C++ if else statement helps when if statement executes false we can use the else statement for executing. It is also used to control the flow of statements based on some conditions.

C++ if else statement Syntax and Flow Chart


//code if condition is true
//code if condition is false


C++ If Else Example:

using namespace std; 
int main() 
   int i = 30; 
   if(i < 10) 
   cout<<"i is smaller than 10"; 
     cout<<"i is greater than 10"; 
     return 0;	 


i is greater than 10

Example 2

#include <iostream>
using namespace std;
int main () {
int x = 30; //variable declaration
//check the condition
if( x < 20 ) {
cout << "x is less than 20;" << endl;//if condition is true then print the following
} else {
  cout<<"a is not less than 20;"<< endl;//if condition is false then print the following
cout<<"The value of x is : "<< x <<endl;
return 0;


a is not less than 20;
The value of x is: 30