In the place where it is written while (s) do begin writes:

Cannot convert string to boolean.

I am writing from a book, the following code is indicated in the book:

 var f: text; s: string; begin assign (f,'dop/file1.txt'); rewrite (f); readln (s); while (s) do begin writeln (f,s); readln (s); end; close (f); end. 

And there the task is to make a program that opens the file and records the entered information from the keyboard. I wrote:

 program TeleFon; var f: text; s: string; begin assign (f,'dop/phone.txt'); reset (f); while not eof (f) do begin readln (f,s); writeln (s); end; close (f); append (f); readln (s); while (s) do begin writeln (f,s); readln (s); end; close (f) end. 

Help, what's wrong?

  • one
    and what kind of book? is there exactly that code? - Grundy
  • one
    it is interesting in what dialect of pascal it compiles ... Although I have seen i ++ in FPC, so little is there in C - style. - pavel
  • one
    while (s <> '') do - Igor
  • "The Basics of Programming" V.M.Bondarev, V.I. Rubinsky, E.G. Kachko - Nikolay Ivanov

1 answer 1

the while condition should be true and exit from the loop, if false

s is a string, but not a boolean, i.e. will be true:

 while(s = 'blabla') 

or

 while(Length(s) > 0) 

but not s

  • Thanks, it helped. - Nikolay Ivanov