by "Chris Burrows" <cfbsoftware@[EMAIL PROTECTED]
>
Nov 3, 2007 at 09:52 AM
"Xcriber51" <ken@[EMAIL PROTECTED]
> wrote in message
news:c023969500341664fb6f74665bbb79e9@[EMAIL PROTECTED]
> Hi
>
> A very minor detail.
>
> If I used a for loop as below, referring to a string 's' (whose length
> doesn't change in the routine),...
>
> FOR i := 0 TO LEN(s$)-1 DO...
>
> ..does BlackBox optimize the expression "LEN(s$)-1" so that it doesn't
> recalculate it at every iteration, or do we have to eliminate that
> manually thus...
>
> len := LEN(s$)-1;
> FOR i := 0 TO len DO ...
>
I haven't inspected the code generated or checked the compiler source but
if
BlackBox was not optimizing the for loop then it would not be in
conformance
with the Component Pascal Language re****t. The definition of a FOR loop in
Section 9.8 of the re****t is:
==============================
FOR v := beg TO end BY step DO statements END
is equivalent to
temp := end; v := beg;
IF step > 0 THEN
WHILE v <= temp DO statements; INC(v, step) END
ELSE
WHILE v >= temp DO statements; INC(v, step) END
END
==============================
i.e. the end value is only evaluated once before the loop starts.
--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp