Skip to content
EspañolWorkspace →

PSeInt Funcion: how to return a result

A routine that works something out and gives back the result, so you can use it inside an expression just like Raiz or Abs. The variable before <- is the one returned.

Template
Funcion
Open it in Codoritmo

Opens the editor with this example loaded. Run it step by step and watch the flowchart.

Worked example

A complete algorithm, ready to copy and run.

funcion-function.psc · 7 lines
Funcion r <- Doble(n)    r <- n * 2FinFuncionAlgoritmo Example    Escribir Doble(21)FinAlgoritmo

Output

Then Escribir Doble(21) shows 42.

This is what the console shows when the example runs.

42

In a flowchart

This is how it appears in a flowchart, with the same shapes Codoritmo draws.

x ← Doble(21)
In the flowchart. Flowchart: a process rectangle reading "x ← Doble(21)", with one arrow in and one arrow out.
Draw the flowchart of your own algorithm →

Template

The general form. Replace what's inside < > with your own data.

Funcion · 3 lines
Funcion resultado <- Nombre(<parametro>)  <acciones>FinFuncion

Examples that use it

Programs from the example library where it appears, from the simplest to the most complete.

  • Linear vs. Binary Search

    Counts the comparisons each search needs on the same sorted list.

    Intermediate
  • Factorial and Power

    Functions that compute a factorial and a power.

    Intermediate
  • Reusable Validation

    Validates the email and age on a sign-up form.

    Intermediate
  • Prime Numbers

    Finds every prime number up to a limit.

    Intermediate
  • GCD and LCM

    Computes the greatest common divisor and the least common multiple.

    Intermediate
  • Quicksort

    Picks a pivot, splits smaller from larger values and sorts each side recursively.

    Advanced
See every Functions example →

More structures

Codoritmo is an independent, open-source project inspired by PSeInt and compatible with its syntax. It is not affiliated with the PSeInt project. Official PSeInt website.