Difference between readLn and read.

The Pascal programming language uses instructions such as read and readLn. What are they?

What is a read statement?

This instruction is intended to provide input from the PC keyboard of various values ​​of variables using the Pascal language. The scheme of using the instruction in question looks simple: like read ("variable value").

In practice, the read instruction is used to ensure that certain data is read from a file and then the values ​​retrieved from the corresponding data are assigned to the variables that are specified when calling the procedure.

If the user makes a mistake when entering data, they do not correspond to any type of variables reflected in the instruction, the program stops executing commands. At the same time, a message appears on the PC screen that an error has occurred in the application.

If the programmer uses several read instructions, then the data will be entered one way or another in one line. The next jump is possible only if the current line ends. However, you can read information placed on another line using the readLn instruction. Let's consider its features in more detail.

What is the readLn instruction?

The essence of the readLn instruction is to set a condition in the program under which:

  • any number entered in the string is assigned to the last variable according to the instruction;
  • The rest of the line is not processed by the program, while the next instruction will require new input.

So, you can enter the instruction:

readLn (C, D); read (E);

And if after that the row 1 2 3 is entered from the keyboard, then the variable C will acquire the value 1, D - 2. But the program will not assign a certain value to the variable E until the user enters a new number.

As with the read instruction, if the user enters an incorrect data type using the readLn command, the program exits and displays an error message.


The main difference between readLn and read is that the first procedure involves the program to jump to the line of the file following the one in which the instructions are written. The second procedure allows the program to read the data placed in the next line, only with the permission of the user - if he presses Enter.

In practice, the readLn instruction is most often used to provide a delay between the result of the application execution and the transition to the next instruction. The corresponding delay lasts until the user presses Enter.

Having defined the difference between readLn and read in the Pascal language, let's fix the conclusions in the table.


read readLn
What do they have in common?
Instructions read and readLn as a whole are intended to solve the same problem - setting conditions for assigning values ​​to certain variables in the Pascal language
What is the difference between them?
This function assumes that the program reads instructions from the next line of the file upon execution of instructions on the current lineThis function assumes that the program reads instructions from the next line of the file upon execution instructions on the current one, as well as provided that the user presses Enter