On Sun, 13 May 2012 15:09:15 +0200
Darius Blaszyk <[email protected]> wrote:
> I'm struggling to convert a simple for loop from C to pascal. The code is
> shown below (as is a trace of the loop parameter values). I'm a bit puzzled
> how this should look elegantly in pascal. Anyone has an idea?
IMHO the C code is short, but not elegant. It would be more elegant if
the j=i is at the end.
> Regards, Darius
>
>
> unsigned nc = 4;
>
> for (unsigned i = 0, j = nc-1; i < nc; j=i++)
> {
> cout << "i:" << i << endl;
> cout << "j:" << j << endl;
> }
>
> loop values are:
> i:0
> j:3
> i:1
> j:0
> i:2
> j:1
> i:3
> j:2
Maybe:
var i,j: integer;
begin
j:=nc-1;
for i:=0 to nc-1 do begin
writeln('i:',i);
writeln('j:',j);
j:=i;
end;
Mattias
_______________________________________________
fpc-pascal maillist - [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal