If Statement In C++


C++ conditional statement allows us to create decisions in C.We know very well that no work is happening without any condition then how can I use this conditional term in programming languages.


There Are Many Way To Use Conditional Statement In C++


  1. If statement

  2. If else statement

  3. Nested If statement

  4. If else-if lader statement

If Statement In C++



if We want to perform conditional work with the only true statement then, if statement is best for us.


Syntax of if statement

if(condition){

stmt;

}


Simple example of if statement in c++

Check A Number Is Positive


#include <iostream>

using namespace std;

int main(){

int x;

cout<<“Enter a Number:”;

cin>>x; //this statemetnt use input number from console

if(x>0){

cout<<“Number is Positive:”<

}

return 0;

}


Output
Enter a Number : 3
Number is Positive: 3