[futurebasic] Re: FOR loop

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1997 : Group Archive : Group : All Groups

From: Ryan Michael McGann <mcrm@...>
Date: Wed, 3 Dec 1997 17:26:27 -0500 (EST)
>> FOR i = X to Y STEP 5
>    execute this!
>> NEXT i
>
>is really executed as ...
>
>> i = X
>> DO
>>  execute this!
>>  IF S >=0 THEN INC(i) ELSE DEC(i)
>> UNTIL i > Y

In C this is definitely true. Here's an interesting C-loop used for linked lists
a lot:
  for (transversal = first; transversal != NULL; transversal = transversal->next)
(this translates in FB like so:)
transversal is a POINTER that starts out holding the same address as first.
The for loop goes along until transversal is NULL (nil or 0). Every iteration
it makes transversal point to the address stored in next (transversal is
really a structure pointer). So it's like a FB Do/While except the addition,
subtraction, whatever you do inside the loop, is done by the compilier (which
results in a faster execution).

Ryan