PSeInt Por Referencia vs Por Valor (pass by reference)
1 example
How it works
When you call a SubProceso, each parameter arrives Por Valor (by value) or Por Referencia (by reference). By value gets a copy: whatever the SubProceso does to it doesn't change the original variable. That's what happens if you don't say anything.
By reference gets the variable itself: if the SubProceso changes it, the change shows outside. That's what you need to swap two values, sort, or give back more than one result.
Arrays are passed by reference even if you don't write it, which is why a SubProceso can sort an array in place.
Short example
The least you need to see it work. Copy it or open it in the editor.
SubProceso Intercambiar(a Por Referencia, b Por Referencia) Definir aux Como Entero aux <- a a <- b b <- auxFinSubProcesoAlgoritmo ReferenceTest Definir p, q Como Entero p <- 1 q <- 2 Intercambiar(p, q) Escribir "p = ", p, ", q = ", qFinAlgoritmoWhat it prints:
p = 2, q = 1Opens in the browser editor, nothing to install.
Solved exercises
Each exercise comes with the full code, its flowchart and a sample run.
By Reference and by Value
Sorts three numbers by swapping them in subprocesses.
Intermediate
In the language reference
The instructions involved, explained one by one.
Other concepts
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.