Skip to the workspace
Pebellslearn by building
Programming Paradigms  ›  Lesson

Structured Programming

Structured Programming 12 minAny program can be built from sequence, selection and iteration, with each block having one way in and one way out.

software design architecture / Structured Programming

Explore each scene at your own pace.

01 · The rule

The rule

Structured Programming

Early programs jumped around with goto: "if the payment failed, go to line 340". Reading one meant tracing arrows back and forth across the page, and a bug could hide in any jump. Structured programming replaced the arrows with a few block shapes, and every language you will use today is built on them, Shelfwise's code included.

The rule

Sequence, choice, repetition — every block has one way in and one way out.

Structured programming says any algorithm can be built from three building blocks:

  • Sequence: steps run one after another.
  • Selection: choose between paths with if / else (or match).
  • Iteration: repeat with for or while.

Blocks nest inside each other, and functions package a block under a name so it can be called like a single step. What is left out on purpose is the unrestricted jump. Without it, each block is entered at the top and left at the bottom, so you can understand it on its own.

def remind_unpaid(orders, today):
    for order in orders:                      # iteration
        if order.unpaid_days(today) > 7:      # selection
            text = reminder_text(order)       # sequence...
            send_email(order.customer, text)  # ...continues

Early return, break and continue are tame jumps that most modern style guides allow, because they exit a block in a way the reader can see. What structured programming ruled out is jumping into the middle of some other block.

The idea comes from the late 1960s, when computer scientists showed the three shapes were enough and argued that goto made programs hard to reason about. It won so completely that most beginners never see a goto at all.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.