HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to PascalVariablesData Types & ConversionOperatorsStringsConditions (if)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
✍️ String
🔁 Condition & Loop
🧩 Function & Procedure
functionprocedure
Pascal›REFERENCE›Function & Procedure
🧩

Function & Procedure

function and procedure.

CommandDescription
functionSubroutine that returns a value.
procedureSubroutine that does not return a value.

function

Try it yourself →

Subroutine that returns a value.

Syntax

function name(x: Type): Type; begin name := ...; end;

Description

The return value is assigned to the function's NAME. Defined before begin.

Example

program H;
function square(x: integer): integer;
begin
  square := x * x;
end;
begin
  writeln(square(5));
end.

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).

procedure

Try it yourself →

Subroutine that does not return a value.

Syntax

procedure name(x: Type); begin ... end;

Description

Does not return a result, just performs an action; called by its name.

Example

program H;
procedure greet(name: string);
begin
  writeln('Hello ', name);
end;
begin
  greet('Alex');
end.

Expected output

Hello Alex

When to use?

Operations with side effects.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code