Procedures, functions, parameters, return values and local variables — OCR ERL and Python
defPROCEDURE and ENDPROCEDURE to define it.RETURN. It just executes its body and control passes back to the caller when ENDPROCEDURE is reached. If a question asks you to return a value, you need a function, not a procedure.RETURN keyword. Use FUNCTION and ENDFUNCTION.RETURN immediately ends the function and sends the value back. Any code after RETURN in that branch does not run. A function must have at least one RETURN statement.price above are also local to the subroutine. They are created when the subroutine is called and destroyed when it ends. They cannot be accessed outside.def keyword. There is no separate PROCEDURE keyword. A Python function with no return statement acts as a procedure.| Feature | OCR ERL | Python |
|---|---|---|
| Procedure start | PROCEDURE name() | def name(): |
| Procedure end | ENDPROCEDURE | (dedent / blank line) |
| Function start | FUNCTION name() | def name(): |
| Function end | ENDFUNCTION | (dedent / blank line) |
| Return value | RETURN value | return value |
ENDPROCEDURE or RETURN is reached, execution returns to the line after the call.ans ← double(5)) or use the call directly in an expression (print(double(5))). If you just write double(5) alone, the return value is lost.printLine that takes a parameter called msg and outputs it. Then call it with the argument "Hello".calculateArea that:width and heightarea and outputPROCEDURE instead of FUNCTION — the question asks for a return value, which requires FUNCTIONRETURN — defining the function but not returning the productcalculateArea(6,4) alone without assigning it| If the task says... | Use... |
|---|---|
| "output / display / print" | PROCEDURE |
| "calculate and return" | FUNCTION |
| "return a value" | FUNCTION |
| "store the result of calling..." | FUNCTION |
PROCEDURE calculateArea(...) but then trying to use a RETURN statement or store the result. PROCEDUREs do not return values — if the question requires a return value, it must be a FUNCTIONRETURN value statement before ENDFUNCTIONcalculateArea(5, 3) on its own. The function runs, RETURN sends 15 back — but nothing stores it, so it is immediately lostarea ← calculateArea(5, 3) or use directly: print(calculateArea(5, 3))PROCEDURE name(params) and ENDPROCEDURE. Call it by name on its own lineRETURN. Define with FUNCTION name(params) and ENDFUNCTION. Capture the return value when callingdef. A function uses return; a procedure-style function has no return statement. Python's def replaces both PROCEDURE and FUNCTIONGet the full resource pack at CSZone.co.uk