Session 03
Control Flow

Control Flow

Master conditional statements, logical operators, and control flow patterns. Learn when to use if/else vs switch, and optimize your decision-making code.

If video doesn't load, watch on Drive

Session Notes

Control Flow

if/else Statements

Master conditional statements, logical operators, and control flow patterns.

Comparison Operators

  • a < b : Less than
  • a > b : Greater than
  • a == b : Equal to
  • a != b : Not equal to

Ternary Operator

variable = (condition) ? true : false;

Switch Statement

Switch is a control structure that chooses one code path based on an integer-like value. When cases are dense numbers (1,2,3...), the compiler builds a jump table for instant O(1) lookup.

switch (age) {
    case 0 ... 4:   // GCC extension
        cout << "Free";
        break;
    default:
        cout << "Paid";
}
Range syntax (0 ... 4) is a GCC extension.