Show in graph
{}

Software → Programming

Control Flow

The order in which statements, instructions, or function calls are executed.

Motivation

Control flow solves the problem of making a program choose, repeat, and sequence behavior instead of running every statement once in order.

Where it fits

It belongs to programming and underpins functions, algorithms, error handling, concurrency, and state machines.

Mental model

Control flow is the set of roads through a program. Conditions choose roads, loops revisit roads, and function calls jump into named roads.

Important details

The common forms are sequencing, branching, looping, early return, exceptions, and function calls.

Common mistakes

  • Hiding too much logic in deeply nested branches.
  • Using clever control flow where simple early returns would be clearer.