On this page
Control Flow & Composition
Prev: State, Variables & Scope | Up: foundations | Next: Functions & Recursion
Rel: Python Control Flow, Imperative & Procedural Programming
Ref: Wikipedia — Control Flow
Tags: #public #prog #programming #foundations
Contents
Structured Control Primitives
By the Structured Program Theorem, any computable algorithm can be expressed with just three primitives:
- Sequence: execute statements in order.
- Selection: branch on conditions (
if/else,switch/match). - Iteration: repeat while a condition holds (
for,while).
Guard Clauses & Short-Circuit Evaluation
Prefer flat guard clauses (early returns on invalid cases) over deeply nested if pyramids:
function process(order):
if order is null: return error("missing order")
if order.items is empty: return error("empty order")
return charge(order)
Boolean AND (&&) and OR (||) short-circuit: the right-hand operand is evaluated only if the left-hand operand does not already determine the result.
Linked from
Related notes
- tuts/programming/foundations Linked here; links to this page; shared tags: #foundations, #prog, #programming
- tuts/programming/foundations/functions_and_recursion Linked here; links to this page; shared tags: #foundations, #prog, #programming
- tuts/programming/foundations/state_variables_and_scope Linked here; links to this page; shared tags: #foundations, #prog, #programming
- tuts/programming/paradigms/imperative_and_procedural Linked here; links to this page; shared tags: #prog, #programming
- tuts/c/fundamentals/control_flow_and_functions links to this page; shared tags: #prog
- tuts/python3/tutorials/core_fundamentals/control_flow Linked here
- tuts/programming/foundations/computational_thinking_and_abstraction shared tags: #foundations, #prog, #programming
- tuts/programming shared tags: #prog, #programming
- tuts/programming/algorithms_and_dsa shared tags: #prog, #programming
- tuts/programming/algorithms_and_dsa/complexity_and_big_o shared tags: #prog, #programming