Learn Pascal Programming with Mc Kenzie

READ and READLN Statements

The READ and READLN statements allow users to input data while the program is running. The statement : read(a); allows the user to input any integer value where a has been declared as an integer.     Var a : integer;

 

Program 6

This program accepts any integer value within the range -32,768 and + 32,767. After the user enters the number the program doubles it and outputs the value.

READLN reads in data from the pointer position into the variable or variables then it discards the rest of the line and moves the data pointer to the first character position of the next line.

READLN and READ operate similarly.

program doubleint(input,output);
Var
    a : integer;
begin
   writeln('Enter an integer value : ');
   read(a);
   
   writeln('When I double ',a,' I get ',a*2)
   end.

Program 6 is made up of three sections:

   1. The Program Heading starts with the word PROGRAM followed by the name of the program. The name of this program is doubleint .The heading ends with the first semi-colon after (input, output) which tells us that the program expects user input before it produces output on screen.

   2. The declaration section begins with Var followed by only one variable a then a colon before the word INTEGER. The last character on the line is the semi-colon.

   3. The body of the progarm starts with the word begin and terminates with the word end.

BSS Main | Previous Lesson | Next Lesson |

InfoDAM Web Technologies©MMX