Article View: comp.lang.misc
Article #5434Re: Loops
From: David Gast
Date: Thu, 07 Apr 1988 23:46
Date: Thu, 07 Apr 1988 23:46
52 lines
1948 bytes
1948 bytes
In article <294@tmsoft.UUCP> mason@tmsoft.UUCP (Dave Mason) writes:
>In a language I designed for my students to implement in my compiler
>course loops look like:
> do
> ...
> while expr
> ...
> od
>where the while can go anywhere & there can be any number of them (or
>until's which are similar but with opposite logic). This leads to
>Pascal style while & repeat loops:
>The do keyword can be followed by 1 or more 'for' clauses,
The semantics are similar to those provided by Algol 68.
>Notes:
>4) all the safety of Pascal subscript calculation
While it is commonly believed that it is impossible to change the
index variable in a for loop, it is possible to do so. Consider the
following program.
program illegal (output);
{This program is not legal pascal, but the compiler does not detect the
error. If the scope of the index variable were local to the for loop
(ala Algol 68), instead of global, then this error would be detected
at compiler time. }
var
i : integer;
procedure illegal_assignment (k: integer);
begin
i := k + 10; {i is the index variable in the for loop}
writeln (i)
end;
begin
for i := 1 to 10 do
begin
illegal_assignment (i);
writeln (i)
end
end.
Although I have not read the latest Pascal standard, the Pascal I used
has many insecurities.
David Gast
gast@cs.ucla.edu
{ucbvax,rutgers}!ucla-cs!gast
Technical Details
Message-ID:
<11047@shemp.CS.UCLA.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!hplabs!sdcrdcf!ucla-cs!lanai!gastReferences:
<2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!pasteur!ucbvax!hplabs!sdcrdcf!ucla-cs!lanai!gast From: gast@lanai.cs.ucla.edu (David Gast) Newsgroups: comp.lang.misc,comp.lang.pascal Subject: Re: Loops Message-ID: <11047@shemp.CS.UCLA.EDU> Date: 7 Apr 88 23:46:25 GMT References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <2773@mmintl.UUCP> <294@tmsoft.UUCP> Sender: news@CS.UCLA.EDU Reply-To: gast@lanai.UUCP (David Gast) Organization: UCLA Computer Science Department Lines: 51