While helping a friend solve a college homework assignment, we ran into a curious exception in the PseInt application when executing the following code in strict mode:
Proceso MiAlgoritmo
Escribir "Ingrese numero de filas"
Leer n
Escribir "Ingrese numero de columnas"
Leer m
Dimension a[n,m]
Dimension v[n]
Dimension datos[n]
//recorrer de filas
Para i <- 1 hasta n Hacer
//recorrer de columnas
Para j <- 1 hasta m Hacer
Escribir "a[",i,",",j,"]:…";
Leer a[i,j]
FinPara
FinPara
FinProceso
Everything looks good, what the hell makes the code fail?
Solution
It is very difficult for sure to tell you all the reasons that would make the execution of an algorithm fail in PseInt, because in itself this tool is a learning tool and is open source, so for now, I will mention the main causes that can cause this error:
Wrong quotes (“ ” instead of "")
Por ejemplo, el siguiente codigo hara fallar la aplicacion:
///Leer un número, luego realizar las siguientes operaciones:
// a) A la variable “X” asignarle el número leído divido por la contante 4
// b) a la variable “X” asignarle su valor sumado con la constante 90
Algoritmo ejercicio3
Definir num, x Como Entero;
Leer num;
x <- num / 4;
x <- x + 90;
FinAlgoritmo
It turns out that the algorithm's error is to include in the comments the quotes like “X” (Unicode Character ““ ”(U + 201C) double quotes to the right or left) instead of "X" (normal double quotes 0x22). It is difficult to notice this error because to our eyes it looks the same, but they are different characters. Avoid including these quotes at all costs as they will make your algorithm fail in the interpreter.
Horizontal ellipsis (…)
The ellipsis (Unicode Character… U + 2026) in certain parts of your code, such as inside instructions to write in defined and indefinite cycles, will cause your code to fail as in the following example:
Proceso MiAlgoritmo
Escribir "Ingrese numero de filas"
Leer n
Escribir "Ingrese numero de columnas"
Leer m
Dimension a[n,m]
Dimension v[n]
Dimension datos[n]
//recorrer de filas
Para i <- 1 hasta n Hacer
//recorrer de columnas
Para j <- 1 hasta m Hacer
Escribir "a[",i,",",j,"]:…";
Leer a[i,j]
FinPara
FinPara
FinProceso
Removing the ellipsis from the instruction will make your code work again!
Final recommendation
I would like to emphasize that PseInt is not a perfect product, of course, so you should be careful. In addition, this type of exception that you could not resolve is probably because you decided to write the code first without testing instruction by instruction to see when its execution stopped and the mentioned exception began to be thrown.
Always go step by step, analyze what each instruction does, and if precisely it begins to fail in a specific instruction, analyze what is special in that line that can cause your code to fail.
Happy coding ❤️!