" if " syntax in C++
now we are going to learn " if " syntax in C++ , how to use it , how to make conditions with it :)
What is " if " syntax for?
You can use if to control the program decisions on what code to perform.
Syntax :
| if ( Condition is TRUE ) {
| // Execute These Statement(s);
| }
|
| else ( Condition is FALSE ) {
| // Execute These Statement(s);
| }
Example :
| int a;
| cin >> a;
|
| if (a==2) {
| cout << " The Number is 2";
| }
|
| else {
| cout << "The Number is not 2";
| }
else if :
If you want to make multiple conditions , use else if !
Example :
| int a;
| cin >> a;
|
| if ( a<3) {
| cout << " The Number is Smaller Than 3";
| }
|
| else if (a==3) {
| cout << " The Number is 3";
| }
|
| else {
| cout << "The Number is Bigger Than 3";
| }
Leave a Comment