Skip to content

9618 · 11.3

Structured Programming

Structured programming is a method of writing computer programs using a limited set of simple building blocks. This approach makes code easier to understand, test, and modify, preventing the chaotic 'spaghetti code' of the past.

Need to know

What you need to know

  • **Sequence:** Instructions are executed in order, one after the other. This is the default flow of any program. `INPUT Name`, then `PRINT 'Hello ', Name`.
  • **Selection:** A decision is made, and the program follows a different path based on a condition. The main constructs are `IF...THEN...ELSE...ENDIF` for binary or nested choices, and `CASE...OF...OTHERWISE...ENDCASE` for selecting from multiple distinct options.
  • **Iteration (Repetition):** A block of code is executed repeatedly. This can be a fixed number of times (`FOR...TO...NEXT`), while a condition is true (`WHILE...DO...ENDWHILE`), or until a condition becomes true (`REPEAT...UNTIL`).

Explanation

Building with Code LEGOs

  1. Decompose the Problem: Start with the main task and break it down into smaller, self-contained sub-problems. This is called top-down design.
  2. Use Standard Blocks: Write the code for each sub-problem using only three types of control structures: Sequence, Selection, and Iteration.
  3. Construct with Modules: Combine the solutions for the sub-problems into a complete program, often using procedures and functions for each sub-task.
  4. Test and Refine: Test each module independently before testing the entire program. This makes finding and fixing bugs (debugging) much simpler.