Skip to content
EspañolWorkspace →

PSeInt SubProceso: examples of splitting a program

14 examples

How it works

A SubProceso groups instructions under a name so you can use them whenever you need. Instead of one long algorithm you get short pieces whose names say what they do: MostrarMenu, DibujarTablero, Intercambiar.

It's written outside the main Algoritmo, between SubProceso and FinSubProceso, and called by writing its name with parentheses. Parameters are the values it receives to work with.

By default parameters are passed by value (the SubProceso gets a copy). If you want it to change the original variable, as when swapping two numbers, declare the parameter Por Referencia.

Short example

The least you need to see it work. Copy it or open it in the editor.

subprocesses-subproceso.psc · 13 lines
SubProceso Linea(n)    Definir i Como Entero    Para i <- 1 Hasta n Hacer        Escribir Sin Saltar "-"    FinPara    Escribir ""FinSubProcesoAlgoritmo Title    Linea(20)    Escribir "  My first program"    Linea(20)FinAlgoritmo

What it prints:

--------------------  My first program--------------------
Open it in Codoritmo

Opens in the browser editor, nothing to install.

Solved exercises

Each exercise comes with the full code, its flowchart and a sample run.

  • Bubble Sort

    Sorts random numbers by swapping neighbors, and stops as soon as they're in order.

    Intermediate
  • Selection Sort

    Finds the smallest of the remaining numbers and puts it in its place.

    Intermediate
  • Insertion Sort

    Inserts each number among the sorted ones, like arranging cards in your hand.

    Intermediate
  • Counting Sort

    Counts how many times each value appears, without comparing numbers.

    Intermediate
  • Binary Search

    Finds a value in a sorted array by halving the range every step.

    Intermediate
  • Linear vs. Binary Search

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

    Intermediate
  • By Reference and by Value

    Sorts three numbers by swapping them in subprocesses.

    Intermediate
  • Modular Menu

    A unit converter with a menu that keeps coming back.

    Intermediate
  • Shell Sort

    Insertion sort between far-apart elements, with a gap that shrinks every pass.

    Advanced
  • Merge Sort

    Splits the array in halves, sorts each one recursively and merges them.

    Advanced
  • Quicksort

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

    Advanced
  • Heap Sort

    Arranges the array as a heap, then takes the largest out again and again.

    Advanced
  • Towers of Hanoi

    Solves the classic tower puzzle step by step.

    Advanced
  • Tic-Tac-Toe

    The classic three-in-a-row game for two players.

    Advanced

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.