C++ Control Statement
C++ control statement or decision-making statement is used to control the flow of program statement according to condition applied.
C++ if Control Statement
An if control statement in C++ is used to control the flow of program statement on behalf of condition applied.
When if condition returns true boolean value, then statement within if block will be executed. And when if condition returns false boolean value, then statement after if the condition will be executed.
Syntax
1 2 3 4 5 6 7 |
if(check_condation){ statement 1; statement 2; ...; } |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <iostream> using namespace std; int main () { int a = 10; int b=20; if( a < b ) { cout << "a is less than b:" << endl; } cout << "value of a is : " << a <<endl << "value of b is : "<< b; return 0; } |
Output
1 2 3 4 5 |
a is less than b: value of a is : 10 value of b is : 20 |