Structured programming is an approach to writing programs that uses subroutines, sequence, selection, and iteration to make code easier to read, test, and maintain. It avoids uncontrolled jumps (like GOTO statements).
The three core constructs are sequence (instructions in order), selection (IF/ELSE), and iteration (loops) — together these can express any algorithm.
A local variable is declared inside a subroutine and only exists while that subroutine is running. It cannot be accessed from outside the subroutine.
A global variable is declared at the top level of a program, outside any subroutine. It can be accessed by any part of the program, including from inside subroutines.
| Feature | Local Variable | Global Variable |
|---|---|---|
| Declared inside/outside subroutine | Inside a subroutine | Outside all subroutines |
| Accessible from where? | Only inside that subroutine | Anywhere in the program |
| Lifetime | Created when subroutine runs; destroyed when it ends | Exists for entire program run |
| Memory use | Released when subroutine ends | Held in memory the whole time |
| Risk | Low — can't be accidentally changed elsewhere | Higher — can be changed from anywhere |
Scope describes where in a program a variable can be used. Local variables have local scope; global variables have global scope.
Modular design (also called decomposition) means splitting a large problem into smaller, manageable modules (subroutines). Each module does one specific job.
| Advantage | Why it helps |
|---|---|
| Easier to test | Each module can be tested independently |
| Team development | Different people can work on different modules |
| Code reuse | Modules can be used in other programs |
| Easier to debug | Faults are isolated to one module |
| Easier to read | Main program reads like a high-level description |
8 questions · 18 marks
| Term | Definition |
|---|
Timed exam conditions.