PSeInt Segun (switch): choose between several options
Picks one path out of many depending on a variable's value, like a menu. Tidier than chaining many Si blocks when you compare the same variable with several values.
- Group:
- Structures
- Template
Segun
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.
Algoritmo Example opcion <- 2 Segun opcion Hacer 1: Escribir "Play" 2: Escribir "Quit" De Otro Modo: Escribir "Not an option" FinSegunFinAlgoritmoOutput
With opcion 2 it shows "Quit".
This is what the console shows when the example runs.
QuitCommon mistake
De Otro Modo catches any value that isn't listed.
In 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.
Segun <expresion> Hacer <valor>: <acciones> De Otro Modo: <acciones>FinSegunExamples that use it
Programs from the example library where it appears, from the simplest to the most complete.
Coffee Shop Menu
Pick a drink from the menu and get the total to pay.
BeginnerCount Vowels
Counts the vowels, spaces and other characters in a text.
IntermediateModular Menu
A unit converter with a menu that keeps coming back.
IntermediateATM
Checks your PIN and lets you check, deposit and withdraw money.
AdvancedContact Book
Add, list and search contacts in a book that grows.
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.