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(ormatch). - Iteration: repeat with
fororwhile.
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) # ...continuesEarly 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.