'Pascal. Unidirectional list. Loop
Here is an example program from a book. I can't stop the "while not eof" loop. I tried to insert in program "Uses crt;", "const CheckEof: boolean=true" and to press "ctrl+Z" while running, it doesn't work.
Program P123;
uses
crt; {My insertion}
type
Adresacelula = ^Celula;
Celula = record
Info: string;
Urm: AdresaCelula;
end;
var
P, Q, R: AdresaCelula;
s: string;
i: integer;
const
CheckEOF: boolean = true; {My insertion}
Procedure Create;
begin
p := nil;
write ('s='); readln (s);
new (r); r^.Info := s; r^.Urm := nil;
p := r; q := r;
write ('s=');
while not eof do {Here is the loop i need to stop}
begin
readln (s); write ('s=');
new (r); r^.Info := s; r^.Urm := nil;
q^.Urm := r; q := r;
end;
end;
Procedure Display;
begin
r := p;
while r<>nil do
begin
writeln (r^.Info);
r := r^.Urm;
end;
readln;
end;
begin
Create;
Display;
end.
Solution 1:[1]
To make the example work, remove the line
const CheckEOF: boolean=true; {My insertion}
and insert CheckEOF:=true; before the Create; call in the main program. Then the program terminates when you press Ctrl-Z.
Your code declares a new variable CheckEOF while you probably want to change CheckEOF of the crt unit.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | FPK |
