Skip to content
EspañolWorkspace →

Segun (switch) in PSeInt: menu and option exercises

5 examples

How it works

Segun picks one path out of several based on a variable's value. It's the natural tool for a menu: the user types 1, 2 or 3 and the program does what each number stands for.

Each case is written as value: with its instructions below. One case can take several values separated by commas, and De Otro Modo (otherwise) catches everything not on the list, like an invalid option.

Segun always compares for equality. If you need ranges (0 to 10, 11 to 20…), use Si conditionals instead.

Short example

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

switch-segun.psc · 13 lines
Algoritmo DayOfWeek    Definir dia Como Entero    Escribir "Day number (1 to 7):"    Leer dia    Segun dia Hacer        1, 2, 3, 4, 5:            Escribir "Weekday"        6, 7:            Escribir "Weekend"        De Otro Modo:            Escribir "No such day"    FinSegunFinAlgoritmo

What it prints:

Day number (1 to 7):User answer: 6Weekend
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.

  • Coffee Shop Menu

    Pick a drink from the menu and get the total to pay.

    Beginner
  • Count Vowels

    Counts the vowels, spaces and other characters in a text.

    Intermediate
  • Modular Menu

    A unit converter with a menu that keeps coming back.

    Intermediate
  • ATM

    Checks your PIN and lets you check, deposit and withdraw money.

    Advanced
  • Contact Book

    Add, list and search contacts in a book that grows.

    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.