what is the condition?
It is a way to know the information that I have set or who enters by a user if it is true or wrong,more conditions for use:
- Less than: a < b
- Less than or equal to: a <= b
- Greater than: a > b
- Greater than or equal to: a >= b
- Equal to a == b
- Not Equal to: a != b
and there are two ways:
1-if :
- Use
if
to specify a block of code to be executed, if a specified condition is true for example:
int x=10;
if (x > 8)
cout << "x is greater than 8";
if (x > 8)
cout << "x is greater than 8";
- Use
else
to specify a block of code to be executed if the same; condition is false for example:
int x=13;
if (x > 18)
cout << "x is greater than 18";
if (x > 18)
cout << "x is greater than 18";
else
cout<<"x is lower than 18";
- Use
else if
to specify a new condition to test, if the first condition is false for example:
int x=13,y=20;
if (x > 18)
cout << "x is greater than 18";
if (x > 18)
cout << "x is greater than 18";
Tags
C++