PSeInt Redimensionar: arrays that grow
2 examples
How it works
An array created with Dimension has a fixed size. Redimensionar changes that size while the program runs and keeps whatever was already stored in its slots.
It helps when you don't know how many values will come: a shopping list that grows with every item, or the numbers someone types until they enter 0. Each time a new value arrives, you grow the array by one slot and store it at the end.
Not every profile allows resizing. If yours doesn't, the classic alternative is to create a large array up front and keep the number of used slots in a variable.
Short example
The least you need to see it work. Copy it or open it in the editor.
Algoritmo GrowingList Definir n, i Como Entero Definir dato Como Caracter n <- 0 Dimension lista[1] Leer dato Mientras dato <> "end" Hacer n <- n + 1 Redimensionar lista[n] lista[n] <- dato Leer dato FinMientras Para i <- 1 Hasta n Hacer Escribir i, ". ", lista[i] FinParaFinAlgoritmoWhat it prints:
User answer: breadUser answer: milkUser answer: end1. bread2. milk
Opens in the browser editor, nothing to install.
Solved exercises
Each exercise comes with the full code, its flowchart and a sample run.
Shopping List
Adds items to a list that grows until you type FIN.
AdvancedContact 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.