There come situations in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations arise in programming also where we need to make some decisions and based on these decisions we will execute the next block of code. For example, in C++ if x occurs then execute y else execute z. There can also be multiple conditions like in C++ if x occurs then execute p, else if condition y occurs execute q, else execute r. This condition of C else-if is one of the many ways of importing multiple conditions.
Decision making statements in programming languages decides the direction of flow of program execution. Decision making statements available in C or C++ are:
- if statement
- if..else statements
- nested if statements
- if-else-if ladder
- switch statements
- Jump Statements:
We will take a look at all of these possibilities.
"Decision Making in C / C++ (if , if..else, Nested if, if-else-if )" by Harsh Agarwal, Geeks for Geeks is licensed under CC BY-SA 4.0