Simple if statement in C++


Simple if statement in C++

Simple if statement in C++ is a very powerful decision making statement and it is used to control the flow of execution of statements.

There are four types of if statement:

In simple if statement, there is only one Condition and depending upon the Condition, a particular set of statements will be executed. The syntax of simple if statement is:

if(Test-Condition)
{
Statement-Block;
}

Test-Condition is a relational or logical expression.

If it is true, Block  of statements referred as Statement-Block gets executed. otherwise Statement-Block will not execute.

Here Statement-Block is a set of valid C++ statements .

Example:

include<iostream>
using namespace std;
int main()
{
  int n=10;
  if(n>0)
    cout<<“Number is +ve";
   cout<<“\nBye”;
   return(0);  
}

Example:

Number is +ve
Bye

In the above program, value of variable n is 10. 

Condition n>0 is true so  cout<<“number is +ve” as well as  cout<<“\nBye” both would be executed.




Spread the love
Lesson tags: if in C++, if statement in c, program of simple if statement in C++, simple if statement in c, syntax of if statement in C++, types of if statement in c
Back to: C++ Programming Notes
Spread the love