4.6.1 How it works
The same + sign that adds numbers concatenates texts. It accepts any combination of String and Character, and the result is always a String: even two single characters form a string of length 2.
Three boxes, "Hola, ", "Ana" and '!', with arrows converging on a larger box with "Hola, Ana!".
ProgramGluing texts
Algorithm Saludo
Define nombre As String <- "Ana";
Write "Hola, " + nombre + '!';
Write 'a' + 'b', " ", length('a' + 'b');
EndAlgorithmOutput
Hola, Ana! ab 2
The program finishes normally.
Concatenation does not convert numbers or booleans to text. To put a number in a message there are two ways: convert it with ConvertirATexto, or separate the pieces with commas in Write.
ProgramA number inside a text
Algorithm ConNumero
Define edad As Integer <- 12;
Write "Tienes " + toText(edad) + " años";
Write "Tienes ", edad, " años";
EndAlgorithmOutput
Tienes 12 años Tienes 12 años
The program finishes normally.
In short
+between texts or characters concatenates them and gives aString.- It does not convert numbers: use
ConvertirATextoor commas inWrite. - It has the same precedence as addition.