Last modified on April 16th, 2021
Conditional Statements in C++
C++ supports the conditional statement.
Some examples of conditional statements are mentioned below;
- Equal to: X == Y
- Greater than: X > b
- Greater than or equal to: X >= Y
- Less than: X < Y
- Less than or equal to: X <= Y
- Not Equal to: X != Y
You can use these conditions to perform different actions for different decisions.
C++ has the following conditional statements:
Statements in the boy of “if” will execute, when the given condition is true
int X = 6;
if(X > 4)
cout << "X is greater than 4";
The given condition on line 2 is true, so line#3, 4, and 5 will execute.
Statements in the boy of “else” will execute, when the given condition in the “if” part is false.
Statements in the boy of “else if” will execute, when the given condition in “if” part is false and the condition in “else if” part is true.
switch conditional statement is used to specify many alternative blocks of code to be executed.
- Why do we need various number systems in computer science? - April 16, 2021
- 5 Best Places to Study Engineering - March 19, 2021
- How Students Can Pick a Good Custom-Paper Writing Service? - March 5, 2021