Re: break statement in a for loop
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: 29 Apr 2007 01:41:51 -0700
a.mil@xxxxxxxxx wrote:
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.
On my system, without the "break", it takes 0.001 seconds (according
to "time"). That's because without the break, the compiler realises
your program does nothing and your for loop is useless, so it removes
it altogether. How about an actual demonstration (a program that does
something useful, such as printing the result of your calculation,
whatever it is you're trying to calculate)?
.
- References:
- break statement in a for loop
- From: a . mil
- Re: break statement in a for loop
- From: a . mil
- break statement in a for loop
- Prev by Date: Re: Common Routine To Call (Almost) Identical Functions
- Next by Date: Re: long integer multiplication
- Previous by thread: Re: break statement in a for loop
- Next by thread: Re: break statement in a for loop
- Index(es):
Relevant Pages
|