Re: break statement in a for loop



Ok, this was a bad fast example, I admit.
Therefore below another example that shows the point.


int main()
{
unsigned long i,j,k,l,n;

for (l=0;l<10000000;l++) {
j=0;
k=10;
n=231;

for (i=1;n>3;j+=8,k+=j,n-=2) {
if (k%n) continue;
i=0;
break;
}
}
return 0;
}


Run this without the break statement and with the break statement and
look at execution time. On my 1.5GHz P4 it takes 1.3s and 13.9s
respectively (!). My store on the factor 100 incorporates a lot more
code.

.



Relevant Pages

  • Re: break statement in a for loop
    ... int main ... Run this without the break statement and with the break statement and ... something useful, such as printing the result of your calculation, ...
    (comp.lang.c)
  • Re: Dharaskars C questions ???
    ... instead of break statement in a switch. ... within loops. ... int main ...
    (comp.lang.c)
  • Re: break statement in a for loop
    ... Richard Heathfield schreef: ... Run this without the break statement and with the break statement and ... int main ...
    (comp.lang.c)
  • Re: break statement in a for loop
    ... Run this without the break statement and with the break statement and ... int main ... Richard Heathfield ... rjh at the above domain, ...
    (comp.lang.c)