Name
ReadLn Procedure
Syntax
procedure ReadLn(var F: TextFile; varVariable; ...); procedure ReadLn(varVariable; ...); procedure ReadLn(var F: TextFile); procedure ReadLn;
Description
ReadLn is just like Read, but
after it finishes reading into all the
Variables, ReadLn skips
the rest of the line and prepares to read the next line. Without any
Variable arguments,
ReadLn skips the rest of the line.
ReadLn cannot read a binary file. It is not a real
procedure.
Tips and Tricks
To
ReadLn, a line ends when it reads a carriage return (#13) or reaches the end of file. The carriage return can optionally be followed by a linefeed (#10) or end of file.When reading strings, you almost certainly want to use
ReadLninstead ofRead. CallingReadto read a long string reads everything up to but not including the line ending. If you callReadagain to read a string, it will read everything up to but not including the line ending, which means it reads an empty string.ReadLnreads the string and then skips the line ending, so you can read the next line of text into the next string.Without a
TextFileas the first argument,ReadLnreads fromInput.
Example
program bmindex;
// Compute a Body-Mass Index, given a person's height in centimeters
// and weight in kilograms. A BMI greater than 26 means a person
// is overweight.
var
Height, Weight: Single;
BMI: Integer;
begin
WriteLn('Enter your height in centimeters: ');
ReadLn(Height);
WriteLn('Enter your weight in kilograms: ');
ReadLn(Weight); BMI := Round((Weight ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access