C++ If...Else

C++ If...Else


C++ If ... Else :
C++ Conditions and If Statements
C++ programming language supports these logical conditions from mathematical expressions as shown in below:
Logical Condition
Description
a < b
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
 
You can use these Statements to perform different actions for different decisions.
  • The if Statement: The if Statement used to specify a block of code to be executed, if a specified condition is true.
  • The else Statement: The else used to specify a block of code to be executed, if the same condition is false.
  • The if-else Statement: The else if Statement used to specify a new condition to test, if the first condition is false.
  • The switch Statement: The switch statement used to specify many alternative blocks of code to be executed.
The if Statement
The if statement is used to specify a block of C++ code to be executed if a condition is true.
The Syntax of if statement is as follows:
if (condition) {
  // if condition is true then block of code to be executed
}
Example :
 
Output :