Re: for loop (c-lang)



On 2007-02-28, Dodgy <Dodgy@xxxxxxxxxxxxxxxxxxxxx> wrote:
for( ; 0 ;)
printf("Why"); ???

For loops will always execute at least once as the end condition is
only ever checked at the end of the code block, where the "next" would
be in basic.

Bollocks. A for loop is a while loop.

Well it might be in Delphi, not sure, can honestly say if I've ever
tried to do a loop zero times in a for, but from the programming
background I come from "for" and "repeat" loops have the comparison at
the end, a "while" has it at the beginning.

Correct for repeat and while, and the C for is equal to the while.

The Pascal for is not equal to while, the biggest difference is that the
number of iterations must be (runtime) constant at the moment the loops
start. Delphi added the check for 0 iterations afaik. (TP didn't)

Note to the assembler fiddlers, for loops with a constant compiletime number
of iterations might look totally different in asm from ones that have a
variable for at least one bound.



.



Relevant Pages

  • Re: Seen java -server optimization vary 50%?
    ... >> I time and print this every hundred iterations. ... >> kill it and start it over the time can be substantially ... >whose most frequently executed loops do a lot of accesses to ... >for an explanation of some important indexing approaches. ...
    (comp.lang.java.help)
  • Re: Analyzing loops with polyhedra libraries
    ... The number of iterations is the number of integer points inside a ... polytope, computed using Ehrhart polynomials: ... you should consider static control loops. ... With "idea" I meant the approach of implementing a loop analyzer ...
    (comp.theory)
  • Re: VB slows down
    ... Probably not unless this is running on a very slow computer. ... said in your first post that it should end ... up with about 96,000 iterations. ... this by removing all the code from within the body of your loops ...
    (microsoft.public.vb.general.discussion)
  • Re: flatten a level one list
    ... 1000 loops, best of 3: ... Peter ...
    (comp.lang.python)
  • Re: Opinion poll: for loop vs while loop with Iterators.
    ... lacks the ability to manipulate the underlying Iterable structure. ... the way to do this is (in pseudo-code:) ... When I was at school, programming in BASIC and Pascal with less flexible for loops, for loops were for a fixed number of iterations known at the start, and while loops for an indeterminate number of iterations. ...
    (comp.lang.java.programmer)