function in for loop
hello,
if I do this
for(int i=0; i<Math.pow(10,2);i++)
;// do nothing loop
does it mean that Math.pow subroutine will be called 101 times ?
should it be like this then:
int end = (int)Math.pow(10,2);
for(int i=0; i><end;i++)
;//do nothing loop
>
[580 byte] By [
taisao003a] at [2007-11-26 20:48:59]

Yep, the second version is much better for exactly the same reason asyou described yourself.kind regards,Jos
> hello,> > if I do this> > [code]> for(int i=0; i<Math.pow(10,2);i++)>; // do nothing loop> es it mean that Math.pow subroutine will be called> 101 times ?Well, 100 anyway. Yes.
> Does it mean that Math.pow subroutine will be called
> 101 times ?
Yes.
> should it be like this then:
> > int end = (int)Math.pow(10,2);
> for(int i=0; i<end;i++)
>; //do nothing loop
>
In most cases it probably doesn't matter. Go with what's easier to understand, or better fits what you're trying to do. Then, if you determine that it is causing a bottleneck, you can change it.
thanks :-Dand 101 times right? i goes from 0 to 99 when it's still inside the loop, (100 times)the last times i = 100, it still need to be checked by the condition (+1) and then it jump out of the loop, so 101 right?
> i goes from 0 to 99 when it's still inside the loop, (100 times)
> the last times i = 100, it still need to be checked by the condition (+1)
> and then it jump out of the loop, so 101 right?
Yep, you're right and warnerja was wrong :-P
kind regards,
Jos (< inventor of the Off-By-One-Error ;-)
> > i goes from 0 to 99 when it's still inside the
> loop, (100 times)
> > the last times i = 100, it still need to be checked
> by the condition (+1)
> > and then it jump out of the loop, so 101 right?
>
> Yep, you're right and warnerja was wrong :-P
>
> kind regards,
>
> Jos (< inventor of the Off-By-One-Error ;-)
Um, no I'm right.
Math.pow(10, 2) == 100, right?
for (int i = 0; i < 100; i++)
will loop 100 times, not 101.
When i is 0, that's the first time.
When i is 1, that's 2.
...
When i is 99, that's 100.
When i is 100, it's out of the loop, because 100 < 100 is false.
Edit: OOPS, now I get it.
It will execute the BODY of the loop 100 times, but it will evaluate pow(10, 2) 101 times.
Never mind, Jos is right.
*Storms off in a huff with head hanging low*
Message was edited by:
warnerja
> > i goes from 0 to 99 when it's still inside the
> loop, (100 times)
> > the last times i = 100, it still need to be checked
> by the condition (+1)
> > and then it jump out of the loop, so 101 right?
>
> Yep, you're right and warnerja was wrong :-P
Yes, both of them were, all three times the four of them posted those five comments. That's the only six things I have to say about these seven topics.
Warnerja confessed:> Never mind, Jos is right.> > *Storms off in a huff with head hanging low**bump*kind regards,Jos (< modesty is my middle name ;'-)
> Warnerja confessed:
>
> > Never mind, Jos is right.
> >
> > *Storms off in a huff with head hanging low*
>
> *bump*
>
> kind regards,
>
> Jos (< modesty is my middle name ;'-)
I don't know how those posts got here! It wasn't me, trust me ;-). Someone like Goldie must have hacked my login and posted those inaccuracies to hurt my reputation! I would never make such a mistake myself ;-)
> > Warnerja confessed:
> >
> > > Never mind, Jos is right.
> > >
> > > *Storms off in a huff with head hanging low*
> >
> > *bump*
> >
> > kind regards,
> >
> > Jos (< modesty is my middle name ;'-)
>
> I don't know how those posts got here! It wasn't me,
> trust me ;-). Someone like Goldie must have hacked my
> login and posted those inaccuracies to hurt my
> reputation! I would never make such a mistake myself
> ;-)
next you'll be telling us your "little brother borrowed my comp." etc
> next you'll be telling us your "little brother> borrowed my comp." etcOh yeah, that was it. It wasn't Goldie, it was my little brother. Yeah, that's the ticket ;-)
> > next you'll be telling us your "little brother
> > borrowed my comp." etc
>
> Oh yeah, that was it. It wasn't Goldie, it was my
> little brother. Yeah, that's the ticket ;-)
't could be that you forgot to activate your seventeen firewalls and swith
ip addresses 1000 times per second ;-)
kind regards,
Jos ;-)
> > > next you'll be telling us your "little brother
> > > borrowed my comp." etc
> >
> > Oh yeah, that was it. It wasn't Goldie, it was my
> > little brother. Yeah, that's the ticket ;-)
>
> 't could be that you forgot to activate your
> seventeen firewalls and swith
> ip addresses 1000 times per second ;-)
>
> kind regards,
>
> Jos ;-)
Don't be silly. I only have fifteen firewalls, and everyone knows you can't switch IP addresses quite that quickly.
> > > > next you'll be telling us your "little brother
> > > > borrowed my comp." etc
> > >
> > > Oh yeah, that was it. It wasn't Goldie, it was
> my
> > > little brother. Yeah, that's the ticket ;-)
> >
> > 't could be that you forgot to activate your
> > seventeen firewalls and swith
> > ip addresses 1000 times per second ;-)
> >
> > kind regards,
> >
> > Jos ;-)
>
> Don't be silly. I only have fifteen firewalls, and
> everyone knows you can't switch IP addresses quite
> that quickly.
you can if you know kung fu 2.0
> > > > next you'll be telling us your "little brother
> > > > borrowed my comp." etc
> > >
> > > Oh yeah, that was it. It wasn't Goldie, it was
> my
> > > little brother. Yeah, that's the ticket ;-)
> >
> > 't could be that you forgot to activate your
> > seventeen firewalls and swith
> > ip addresses 1000 times per second ;-)
> >
> > kind regards,
> >
> > Jos ;-)
>
> Don't be silly. I only have fifteen firewalls, and
> everyone knows you can't switch IP addresses quite
> that quickly.
You should use IPv6 for a fifty percent speed gain ;-)
kind regards,
Jos (not: 127.0.0.42, oh now it is, I mean *was* ;-)
JosAHa at 2007-7-21 18:04:24 >

> next you'll be telling us your "little brother> borrowed my comp." etcYou sick little brother of course, who's only dream is to be a great java developer ;-P
> > next you'll be telling us your "little brother
> > borrowed my comp." etc
>
> You sick little brother of course, who's only dream
> is to be a great java developer ;-P
w.r.t. Gosling that implies that you have to wear funny T-shirts, glasses
and be almost bald-headed except for a little beard?
kind regards,
Jos (< long haired piece of lazy scum ;-)
JosAHa at 2007-7-21 18:04:24 >
