That would make perfect sense...if there is no reference to the loop
variable in the loop, then the order in which it is done is not going to
matter....

John


-----Original Message-----
From: Neven MacEwan [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 7 August 2007 10:03 p.m.
To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] for..loop


John

This is where 'optimisation' comes in it  would count down  because  
'jump zero' is a single instruction but
would only apply this if there was no reference to the loop var ie

var
  i: integer

for i:= 0 to 3 do
begin
  write('hello')
end;

but don't do
for i:= 0 to 3 do
begin
end;

because many optimisers will remove this loop altogether

Neven

> 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: [email protected]
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to [EMAIL PROTECTED] with 
> Subject: unsubscribe
>
> __________ NOD32 2245 (20070506) Information __________
>
> This message was checked by NOD32 antivirus system. 
> http://www.eset.com
>
>
> _______________________________________________
> NZ Borland Developers Group - Delphi mailing list
> Post: [email protected]
> Admin: http://delphi.org.nz/mailman/listinfo/delphi
> Unsubscribe: send an email to [EMAIL PROTECTED] with 
> Subject: unsubscribe
>
>
>   

__________ NOD32 2245 (20070506) Information __________

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


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

Reply via email to