Decision-Making Statements
7. Decision-Making Statements
Decision-making statements help a program choose between different actions. They make code smarter by allowing it to react differently depending on the situation. This is one of the most important parts of programming because not every case is the same.
a. If Statement
The if statement checks a condition and runs code only when the condition is true. If the condition is false, the code inside the if block is skipped. This is useful when you want a program to respond only in specific situations.
For example, if a student’s marks are above the pass mark, the program can display “Passed.” If the condition is not true, nothing happens in that block. The if statement is simple but very powerful because it introduces the idea of decision making.
b. If-Else Statement
The if-else statement gives the program two choices. If one condition is true, one block of code runs. If it is false, the else block runs instead. This is helpful when the program needs to choose between two clear outcomes.
For example, if the age is 18 or more, the program may display “Eligible.” Otherwise, it may display “Not eligible.” This gives the user a complete response instead of only handling one case. Beginners often find if-else easy to understand because it mirrors everyday choices.
c. Nested If Statements
Nested if statements mean placing one if statement inside another. This is used when one condition depends on another. It helps when a decision needs multiple layers of checking.
For example, a program might first check whether a user is logged in. If yes, it can then check whether the user has admin access. Only if both conditions are satisfied will the program allow certain actions. Nested ifs are useful, but beginners should use them carefully so code does not become too hard to read.
d. Match/Switch Statements
Match or switch statements are used when a program must choose from many possible values. Instead of writing many separate if-else checks, the program compares one value against several cases and runs the matching block. This often makes the code cleaner and easier to organize.
For example, if a number represents a day of the week, the program can display the correct day name. If a menu choice is 1, 2, or 3, the program can run a different action for each option. Match/switch statements are especially useful in menus, command handling, and option-based programs.










