break statement in a for loop



I am programming for code-speed, not for ansi or other nice-guy stuff
and I encountered the following problem:

When I have a for loop like this:

b=b0;
for (a=0,i=0;i<100;i++,b--) {
if (b%i) continue;
a=1;
}

I want to break out of the loop -fast- after a==1. When I put a break
after it like in

b=b0;
for (a=0,i=0;i<100;i++,b--) {
if (b%i) continue;
a=1;
break;
}

the former fast loop turns into a horribly (factor 100 or so...) slow
one, so better to use no break at all in my opinion.

Does anyone know exactly -why- the break statement makes the loop so
slow??
Isn't it just an extra "jmp" in assembler equivalent code? I compared
both assembled outputs with and without the break statement, but they
really look quite different.. ?! I optimize with -O3 using gcc.

.



Relevant Pages

  • make buildkernel KERNCONF=CUSTOM errors!!!
    ... case label not within a switch statement ... break statement not within loop or switch ...
    (freebsd-questions)
  • Re: break statement in a for loop
    ... When I have a for loop like this: ... the former fast loop turns into a horribly slow ... Does anyone know exactly -why- the break statement makes the loop so ... Isn't it just an extra "jmp" in assembler equivalent code? ...
    (comp.lang.c)
  • Re: break statement in a for loop
    ... When I have a for loop like this: ... Does anyone know exactly -why- the break statement makes the loop so ... authors of your compiler ... Before the optimiser gets his hands on the code, ...
    (comp.lang.c)
  • Re: breaking out of multiple nested loops
    ... //it only breaks only from last for loop. ... and you should restructure the code so it no longer needs it. ... Some people argue against the use of the break statement at all, ... and say that each chunk of code should have a single entry point ...
    (comp.lang.c)
  • Re: Do we need a DCL debugger?
    ... >> BREAK statement that allows you to break out of the loop prematurely. ... >> JUMPOUT label ... > the nesting level, which in those days was only reset by reading ...
    (comp.os.vms)