Comprehensive notes for Chapter 11 Decision Constructs. Covers Control Structures, if, if-else, switch statements, and Conditional Operator.
Definition: Statements used to control the flow of execution in a program.
Definition: Simpson selection structure. Executes a block of code only if a specified condition is true.
Syntax: if (condition) { statement(s); }
If the condition is false, the code block is skipped.
Definition: Two-way selection structure. Executes one block if condition is true, and another block if condition is false.
Syntax: if (condition) { statement1; } else { statement2; }
Definition: An if statement inside another if statement.
Working: Inner if is executed only if the outer if condition is true. Used for complex multiple-condition checks.
Definition: Used to choose one block from many options.
Syntax: if (cond1) { ... } else if (cond2) { ... } else { ... }
Conditions are checked in sequence. First true condition executes its block. If none are true, the final else block executes.
Definition: Multi-way selection structure. Alternative to nested if-else-if when checking a single variable against many constant values.
Syntax: switch(expression) { case val1: ... break; case val2: ... break; default: ... }
Definition: Ternary operator (takes 3 operands). Shorthand for simple if-else.
Syntax: (condition) ? true_statement : false_statement;
Example: max = (a > b) ? a : b; assigns the larger of a and b to max.