A program is nothing but the execution of a sequence of one or more instructions. In a monolithic program, the sequences of instructions are executed in the same order as they appear in the program. Quite often, it is desirable to alter the sequence of the statements in the program depending upon certain circumstances. In practical applications, there are a number of situations where one has to change the decisions based on the requirements/conditions. This involves taking a decision to see whether a particular condition is satisfied
Decision-making statements in a programming language help the programmer to transfer the control from one part of the program to another part. Thus, these decision-making statements enable the programmer to determine the flow of control.
On the basis of applications it is essential to:
- Alter the flow of a program
- Test the logical conditions and
- Control the flow of execution as per the selection.
These conditions can be placed in the program using decision-making statements. C++ language supports the decision making-statements as listed below.
- The if statement
- The if-else statement
- The nested if-else statements.
- The else-if ladder
- The switch case statement.
- The break statement
- The default keyword
The decision-making statement checks the given condition and then executes its sub-block. The decision statement decides the statement to be executed after the success or failure of a given condition.