Working of if-else statement
- Control falls into the if block.
- The flow jumps to Condition.
- Condition is tested.
- If Condition yields true, goto Step 4.
- If Condition yields false, goto Step 5.
- The if-block or the body inside the if is executed.
- The else block or the body inside the else is executed.
- Flow exits the if-else block.
C++ if else Statement
Decision Making in C++ helps to write decision-driven statements and execute a particular set of code based on certain conditions.
The if statement alone tells us that if a condition is true it will execute a block of statements and if the condition is false it won’t. But what if we want to do something else if the condition is false. Here comes the C++ else statement. We can use the else statement with if statement to execute a block of code when the condition is false.