Pascal (was Re: for(;;) vs. while(1) is a draw)
Richard A. O'Keefe
ok at goanna.cs.rmit.oz.au
Wed May 30 17:23:04 AEST 1990
In article <1751 at tkou02.enet.dec.com>, diamond at tkou02.enet.dec.com (diamond at tkovoa) writes:
: >Um, I've recently had a lot more contact with people from a Pascal
: >background than I really wanted. Quickly now, what's wrong with this:
: 1> program main;
--------------------^ (output) should be declared because it is used!
: 2> var i: integer;
: 3> procedure p(n: integer);
: 4> begin
: 5> for i := 1 to n do write(' ');
------------------------^ the loop control variable must be LOCAL
: 6> writeln(i);
----------------------------^ the loop control variable is now UNDEFINED
: 7> end;
: 8> begin
: 9> p(10);
:10> end.
: >(I count three violations of the Pascal Standard.)
: Then read the Pascal Standard and count again. There is one violation.
Here are slightly edited error messages from a compiler:
Line 5: FOR-loop control variable must be declared at this level
Line 5: Standard file "output" must be declared by PROGRAM statement
Line 6: Must assign value before using variable
Line 6: Standard file "output" must be declared by PROGRAM statement
: (Did you think that Pascal lacks a null statement?)
No of course I didn't. I do hope that winning this argument helps to
convince people that I'm right about the superiority of for (;;) over
while (1) as well, but somehow I don't suppose it will. Too bad.
--
"A 7th class of programs, correct in every way, is believed to exist by a
few computer scientists. However, no example could be found to include here."
More information about the Comp.lang.c
mailing list