Jump to content
  • Advertisement
Sign in to follow this  
TEUTON

writing infinite loop

This topic is 4496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This was asked from my friend in an interview. Which is a efficient way of writing an infinite loop?? I guess all are same, what do you think guys?

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure what an "efficient" way would be to writing an infinite loop, since it is an infinite loop, but I'd guess: while(1){ } or for(;;){ } So yea, the question needs more context to make sense. (The question they asked, not you)

Share this post


Link to post
Share on other sites
Is while(true); more efficient than while(1); ?

I would guess so but im not sure, my theory is that 1 would have to evalute to true first, not sure about for(;;);

Share this post


Link to post
Share on other sites
Is while(true); more efficient than while(1); ?

I would guess so but im not sure, my theory is that 1 would have to evalute to true first, not sure about for(;;); or maybe the bool would have to change to an int type.

Share this post


Link to post
Share on other sites
Quote:
Original post by simon10k
Is while(true); more efficient than while(1); ?

I would guess so but im not sure, my theory is that 1 would have to evalute to true first, not sure about for(;;);


No. Even if true was a macro (or even a constant), it would be replaced at compile-time.

Share this post


Link to post
Share on other sites

void slow_infinite_loop()
{
double f = 0;
while(f < 1) {
f = rand_float();
f = secant(f) * cosine(f);
f /= 2.0;

//do stuff here
}
}


If the infinite loop is intentional, then chances are it won't get much faster than it already is.

CM

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!