function
Subroutine that returns a value.
Syntax
function name(x: Type): Type; begin name := ...; end;
Description
The return value is assigned to the function name (or Result). It is defined before begin. div is integer division, mod is remainder.
Example
Loading editor…
Expected output
25
When to use?
Preventing code repetition.
Common mistakes
- ⚠️ The return value is assigned to the function name: square := x*x; (no return keyword).