Skip to content

9618 · 11.2

Constructs

Programming constructs are the fundamental instructions that tell a computer what to do and in what order. They are the basic building blocks for creating any algorithm, just like a recipe is built from simple steps.

Need to know

What you need to know

  • `IF...THEN...ELSE...ENDIF`: Used for single or binary choices. The `ELSE` part is optional. You can chain them using `ELSEIF` for multiple conditions.
  • `CASE...OF...OTHERWISE...ENDCASE`: Ideal for selecting one path from many, based on the value of a single variable or expression. It's often cleaner than multiple `ELSEIF`s.
  • Nested Selection: An `IF` or `CASE` statement can be placed inside another one to handle more complex, multi-level conditions.
  • Conditions use relational operators (`=`, `<>`, `<`, `>`, `<=`, `>=`) and logical operators (`AND`, `OR`, `NOT`).

Explanation

The Algorithm's Recipe Book

  1. **Sequence:** Code runs line by line, in the order it's written, like following a simple list of instructions.
  2. **Selection (IF/CASE):** The program makes a decision. It checks a condition and chooses which block of code to run next.
  3. **Iteration (Loops):** A block of code is repeated. This can be a set number of times (`FOR`), while a condition is true (`WHILE`), or until a condition becomes true (`REPEAT`).
  4. **Nesting:** Constructs can be placed inside one another. For example, a loop (`FOR`) might contain a decision (`IF`) to handle different cases on each repetition.