Simple if statement in C++
Simple if statement in C language 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:
Simple if statement in C++
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 conditional 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 .
Program to demonstrate simple if statement in C++. |
#include<iostream> using namespace std; int main() { int n=10; if(n>0) cout<<“number is +ve”; cout<<“\nBye”; return(0); } |
Output |
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.