if statement.

if statement

Syntax of the if statement

if (condition)

{
  statement(s);
}

  • The if statement evaluates the test expression inside parenthesis.
  • If test expression is evaluated to true, statements inside the body of if is executed.
  • If test expression is evaluated to false, statements inside the body of if is skipped.


  • From the flowchart it is clear that if the if condition is true, statement is executed; otherwise it is skipped. 
  • The statement may either be a single or compound statement.
#include <iostream>
using namespace std;
int main ()
{
   // Declaring local variable
   int num = 5;
   // check the boolean condition
   if( num > 4 )
   {
       cout << "num is greater than 4" << endl;
   }
   cout << "Given number is : " << num << endl;
   return 0;
}

Output
num is greater than 4
Given number is : 5

Post a Comment

Previous Post Next Post