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.
- Group:
- Structures
- Template
Funcion
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 r <- Doble(n) r <- n * 2FinFuncionAlgoritmo Example Escribir Doble(21)FinAlgoritmoOutput
Then Escribir Doble(21) shows 42.
This is what the console shows when the example runs.
42In a flowchart
This is how it appears in a flowchart, with the same shapes Codoritmo draws.
Template
The general form. Replace what's inside < > with your own data.
Funcion resultado <- Nombre(<parametro>) <acciones>FinFuncionExamples 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.
IntermediateFactorial and Power
Functions that compute a factorial and a power.
IntermediateReusable Validation
Validates the email and age on a sign-up form.
IntermediatePrime Numbers
Finds every prime number up to a limit.
IntermediateGCD and LCM
Computes the greatest common divisor and the least common multiple.
IntermediateQuicksort
Picks a pivot, splits smaller from larger values and sorts each side recursively.
Advanced
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.