Forum Navigation
You need to log in to create posts and topics.

Re: FOR loop

Posted by: friedo <friedo@...>

On Tue, 2 Dec 1997, PEREIRA CHRISTOPHER A wrote:

> I was told in my 'Introduction to C programming' class that the FOR-NEXT
> structure is executed as a special case of the DO-UNTIL structure.
>
> FOR i = X to Y STEP S
> 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
>
> My instructor _could_ have been wrong ...
>
> _Chris
>

That's interesting. it makes sense...the second structure is exactly what
the logic of the FOR loop should be. If, in the DO UNTIL structure, i is
initially greater than Y, would C execute the loop or just skip it? I'm C
impaired.

- Mike