Pascal Input/Output

The aim / purpose of computer programs is for it to produce desired output or accept relevant data. Inorder to feed data into the program or receive data, input and output statements are essential.

Pascal has some standard identifiers for this purpose, these include;read, readln, write and writeln.

Data input
There are two standard pascal identifiers used to enter / feed data to a program, these are; read and readln.

The read statement
It is used to insert data into the program from the screen and does not insert a carriage return on the line meaning that the cursor remains on the same line after reading. Example: var area, base, height: real; begin read(base, height); area:=1/2*(base*height); writeln(area); end. ===The readln statement=== This statement is used to insert data into the program from the screen and it inserts a carriage return on the line after reading a data item, meaning that after a single data item has been read from a line, the next data to be read will be from the next line even if there was other data on that line it wont be read(it will be skipped). Example: var area, base, height: real; begin readln(base, height); area:=1/2*(base*height); writeln(area); end.

Data output
There are two standard pascal identifiers used to extract / output data from a program, these are; write and write.

The write statement
It is used to output data from the program to the screen and does not insert a carriage return on the line meaning that the cursor remains on the same line after outputting in that the next output will be on the same line. Example: var area, base, height: real; begin base:=50; height:=35; area:=1/2*(base*height); write(area:4:5); end. ===The writeln statement=== This statement is used to extract data from the program to the screen and it inserts a carriage return on the line after output meaning that the cursor moves to the next line extracting data. the next output will appear on a different line. Example: var area, base, height: real; begin read(base, height); area:=1/2*(base*height); writeln(area:5:4); end.

Comments
Pascal comments can be entered in two ways: Example: (* Program to compute the volume of a sphere *) { Computation of income tax for the salaried people for November 2011}
 * 1) by enclosing within (* .. comment.. *)
 * 2) by enclosing within { ..comment.. }