[DUG] for..loop

John Bird johnkbird at paradise.net.nz
Tue Aug 7 19:16:09 NZST 2007


That sort of surprises me - surely counting down instead of up would spoil
the expected logic of a loop in some cases????

Eg a trivial example, getting the first word from a string...

Function getfirstword(aline:string):integer;
Var
i:integer;
For i:=1 to length(aline) do
Begin
   if(aline[i]=' ') then
   begin
     result:=copy(aline,1,i-1);
     exit;
   end;
End;

I would indeed be rather upset if I got either the last word back, or the
whole of the line except the last word.
This is a made up example, but I am sure a lot of "for" loops might be
looking for the first instance of something...are you saying we cannot rely
on the order the loop runs???

John

> p.s. has anyone else noticed that sometimes when you step through a 
> for loop the counter actually counts down (in the debugger) (even if 
> it set to count up).  This was the case sometimes in D6 if I recall 
> correctly.
>

It's an optimisation thing.  Counting down to 0 is more efficient than
counting up.

Sean

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe

__________ NOD32 2245 (20070506) Information __________

This message was checked by NOD32 antivirus system. http://www.eset.com




More information about the Delphi mailing list