# Procedures &amp; Functions

> Cambridge Assessment International Education (CAIE) Pseudocode Reference Guide
> Applicable Syllabus: **IGCSE &amp; A Level**

Modular Cambridge pseudocode subroutines: PROCEDURE with CALL, FUNCTION with RETURN, and parameter passing by value (BYVAL) and reference (BYREF).

---

Procedures perform actions and are invoked with `CALL`. Functions return a single value via `RETURN` and are called as part of an expression (not with `CALL`). IGCSE uses ordinary typed parameters. Explicit pass-by-value (`BYVAL`, default) and pass-by-reference (`BYREF`) modes are AS &amp; A Level (9618) extensions.

### Procedures (CALL)

```pseudocode
// Without parameters
PROCEDURE DefaultSquare()
   CALL Square(100)
ENDPROCEDURE

// With parameters
PROCEDURE Square(Size : INTEGER)
   FOR Side &lt;- 1 TO 4
      CALL MoveForward(Size)
      CALL Turn(90)
   NEXT Side
ENDPROCEDURE

CALL Square(50)
```

### Functions (RETURN)

```pseudocode
FUNCTION Max(Number1 : INTEGER,
             Number2 : INTEGER)
             RETURNS INTEGER
   IF Number1 &gt; Number2 THEN
      RETURN Number1
   ELSE
      RETURN Number2
   ENDIF
ENDFUNCTION

// Called as part of an expression
OUTPUT &quot;Penalty = &quot;, Max(10, Distance*2)
```

### Passing by Reference (BYREF)

```pseudocode
// BYREF allows the procedure to modify the caller&#39;s variables directly
PROCEDURE SWAP(BYREF X : INTEGER, BYREF Y : INTEGER)
   Temp &lt;- X
   X &lt;- Y
   Y &lt;- Temp
ENDPROCEDURE

// Note: If not specified, BYVAL (pass by value) is assumed.
// Parameters should NOT be passed BYREF to a function.
```


---

* Previous Topic: [Iteration (Loops)](https://csmasters.dev/docs/pseudocode/iteration.md)
* Next Topic: [File Handling](https://csmasters.dev/docs/pseudocode/file-handling.md)
