[For] A 'For to' which reacts like a 'for downto'

Please discuss general Delphi programming topics here.

[For] A 'For to' which reacts like a 'for downto'

Postby Dave_lopez » June 15th, 2004, 8:27 am

Hi everybody,

I got a this extract of code which uses a for:

Code: Select all
For Cpt:=8 to 128 do
  D[CPT] := S.D[CPT];


What's happening ?
Answer:

D[121] := S.D[121];
D[120] := S.D[120];
D[119] := S.D[119];
...
D[2] := S.D[2];
D[1] := S.D[1];

It is driving me crazy ...

Thanx in advance ...
Destiny exists ...
Dave_lopez
Member
Member
 
Posts: 3
Joined: May 12th, 2004, 9:54 am
Location: Paris

Postby Kambiz » June 15th, 2004, 9:17 am

The downward for loop is faster than the upward one. Because of that, when direction of the for loop variable doesn't affect the result, the compiler optimizes the code and generates the downward loop.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 6 guests

cron