Skip to content

SpecificationI · Overview

1.5

How a program ends

Every run ends in one of six states: it finished well, it failed, it is waiting for input, it is waiting for the outside world, it was cancelled or it ran out of a limit.

Markdown version

1.5.1 How it works

When a program stops moving forward, the engine says exactly why. That reason is called the termination and it is always one of these six:

TerminationWhat it meansCan it continue?
completedThe algorithm reached its EndAlgorithmNo: it finished
failedA runtime failure stopped itNo
awaiting_inputA Read needs a value that has not arrived yetYes, once it receives it
awaiting_effectIt is waiting for an answer from a file, clock or networkYes, once it receives it
cancelledWhoever was running it stopped itNo
limit_reachedIt ran out of a statement, memory or depth budgetNo
Figure 1.5-1.From "running" one of six states is reached. Two of them are pauses you can come back from.

At the top, the running state. An arrow goes down to a box with the four final terminations: completed, failed, cancelled and limit_reached. Two side arrows lead to the pauses awaiting_input and awaiting_effect, which resume.

The normal case is completed:

ProgramEnds normally

Algorithm Bien
  Write "Fin del programa";
EndAlgorithm

Output

Fin del programa

The program finishes normally.

A runtime failure stops the program at the exact statement. What was already written is kept:

ProgramEnds with a failure

Algorithm Falla
  Define divisor As Integer <- 0;
  Write "Antes del fallo";
  Write 10 Div divisor;
  Write "Esto nunca se escribe";
EndAlgorithm

Output

Antes del fallo

Diagnostics

  • divisionByZero · error · 4:12 · Division by zero

The program finishes with an error.

If a Read receives no value, the program pauses. The editor asks you for the data and the run continues where it stopped:

ProgramWaits for input

Algorithm Espera
  Define edad As Integer <- 0;
  Write "¿Cuántos años tienes?";
  Read edad;
  Write "El año que viene tendrás ", edad + 1;
EndAlgorithm

Output

¿Cuántos años tienes?

The program is left waiting for input.

In short

  • Six possible terminations; only completed means everything went well.
  • A failure stops the program at the exact statement and keeps what was already written.
  • awaiting_input and awaiting_effect are pauses that resume.