Skip to content
EspañolWorkspace →

PSeInt for loop (Para) exercises

24 examples

How it works

Para repeats a block a known number of times. A counter variable starts at one value, moves on every pass, and the loop ends once it goes past the final value: Para i <- 1 Hasta 10 Hacer makes ten passes.

Con Paso (step) changes how much the counter moves. Con Paso 2 counts in twos, and Con Paso -1 counts backwards, which is handy for countdowns or walking an array from the end.

Pick Para when you know the number of passes before you start (the 10 rows of a table, the n items of an array). If it depends on something that happens inside, use Mientras or Repetir.

Short example

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

for-loops-para.psc · 8 lines
Algoritmo TimesTable    Definir n, i Como Entero    Escribir "Which times table?"    Leer n    Para i <- 1 Hasta 5 Hacer        Escribir n, " x ", i, " = ", n * i    FinParaFinAlgoritmo

What it prints:

Which times table?User answer: 77 x 1 = 77 x 2 = 147 x 3 = 217 x 4 = 287 x 5 = 35
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.

  • Times Table

    Prints the multiplication table for the number you choose.

    Beginner
  • Countdown

    A rocket launch countdown that ticks second by second.

    Beginner
  • Grade Average

    Stores five grades in an array and finds the average and the highest.

    Beginner
  • Name Initials

    Gets the initials of a full name.

    Beginner
  • Fibonacci Sequence

    Prints the first terms of the Fibonacci sequence.

    Beginner
  • Drawing Shapes

    Draws a square and a triangle with asterisks.

    Intermediate
  • Store Inventory

    Records the stock of each product and flags what to restock.

    Intermediate
  • 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
  • Linear vs. Binary Search

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

    Intermediate
  • Palindromes

    Checks whether a phrase reads the same forwards and backwards.

    Intermediate
  • Count Vowels

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

    Intermediate
  • Factorial and Power

    Functions that compute a factorial and a power.

    Intermediate
  • Prime Numbers

    Finds every prime number up to a limit.

    Intermediate
  • Compound Interest

    Watch your savings grow year by year.

    Intermediate
  • Weekly Sales

    A table of sales by branch and day, with totals.

    Advanced
  • 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
  • Heap Sort

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

    Advanced
  • Caesar Cipher

    Encrypts a message by shifting each letter of the alphabet.

    Advanced
  • Roman Numerals

    Converts a number from 1 to 3999 into Roman numerals.

    Advanced
  • Class Grade Book

    Records three grades per student and builds a class report.

    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.