This page explains a basic Pascal instruction. If you want to see how to make your own instructions, see Procedures and Functions.
This article is part of the Getting Started series

The READ and READLN instructions read a variable from the keyboard. The comand will continue to read until ENTER is pressed (with an exception). In contrast with READ, READLN reads the variable and, when the user pressed ENTER, it moves the cursor on the next line.

These instructions can read one variable or more variables. For example:

read (x); {reads the variable x}
read (a,b,c); {reads a, then reads b, then reads c}

Reading more variablesEdit

When using readln, the user will have to press ENTER each time it inputs a new variable. When using read, the variables can be read without pressing ENTER each time, but only once, but separing the variables with SPACE. For example if you have:

read (a,b,c);

then the user has two two possibilities of inputting of the variables:

  1. inputing the first, then ENTER, then inputing the second, then ENTER again and inputing the third, then ENTER again
  2. inputing the first, leaving a space, inputing the second, then leaving another space, then inputing the third, then pressing ENTER

Additionally, when read is found inside a FOR...DO cycle, the variables read can also be inputed with spaces. For example, this works in the folowing situation:

for i:=1 to n
read (v[i]);

This situation is equivalent to read(v[1],v[2],v[3],...,v[n]);.

See alsoEdit