C++ conditional statements allow you to make decisions based on the result of a condition. These statements are called Decision Making Statements or Conditional Statements. This tutorial will briefly teach you about the various Decision Making statements in C++.
So far, we have seen that in a C++ program, all the statements are executed sequentially in the order in which they are written and appeared. This occurs when there is no jump-based statement or repetition of specific calculations. But some situations may arise where you may have to change the order of statements' execution depending on particular conditions. It involves a kind of decision making from a set of calculations. It is to be noted that C++ assumes any non-zero or non-null value as true
and if 0
(zero) or null
treated as false
.
This type of structure requires that the programmers indicate several conditions for evaluation within a program. The statements will get executed only if the condition becomes true
and optionally, an alternative statement or set of statements will get executed if the condition becomes false
.
The flowchart of the Decision-making technique in C++ can be expressed as follows:
C++ languages have such decision-making capabilities within their program by the use of following the decision making statements:
- if Statement
- if-else Statement
- else-if Statement
- goto Statement
- switch Statement
- Conditional Operator
These above decision-making statements are described in more detail in subsequent tutorials.