" if " syntax in C++


if syntax in cpp

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.

if syntax in cpp

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";
       | }


No comments

Powered by Blogger.