Preview
IB DP Computer Science — B2 Programming — Programming constructs | SL | B2.3.4
📋 What You Will Learn
- Construct functions with parameters and return values as reusable blocks of code
- Call the same function with different inputs and predict each result
- Explain the principle of scope: local versus global variables
- Decompose a program into modules and explain how a main routine coordinates them
- Evaluate the benefits of modularization for structure, reuse, testing and maintenance
🧰 Why This Matters A chef doesn't reinvent "dice an onion" for every dish — it's one practised routine, applied to whatever ingredient today's recipe needs. A function is exactly that: a named, reusable routine whose inputs change from call to call while the steps stay the same.
Functions: Reusable Blocks with Inputs and an Output
- A function is a named block of code that performs one task; it may take parameters (its inputs) and may return a value (its output).
- Parameters vs arguments: parameters are the named placeholders in the