Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


for and while inifite loops


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Kalner   Members   -  Reputation: 120

Like
0Likes
Like

Posted 28 December 2012 - 04:22 PM

So I noticed that both for and while loops have a infinite loop option, is there any difference between them? 



Sponsor:

#2 Cornstalks   Crossbones+   -  Reputation: 6991

Like
4Likes
Like

Posted 28 December 2012 - 04:35 PM

Assuming you mean while (true) vs for (;;) vs do { } while (true), no, there's no technical difference.
 
However, I've seem some compilers generate a warning* for while (true) and do { } while (true) but not generate a warning for for (;;), in which case for (;;) may be preferred to avoid a warning.
*For example, see this question.

Edit: I just realized this question was tagged Java and was assuming C or C++ when I was talking about the warning stuff. It's the same in Java as it is in C and C++ in that there's no real technical difference between these infinite looping methods, but the compiler warning issue I talked about isn't relevant in Java.


Edited by Cornstalks, 28 December 2012 - 05:06 PM.

[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#3 Kalner   Members   -  Reputation: 120

Like
0Likes
Like

Posted 28 December 2012 - 04:53 PM

Thanks



#4 Mussi   Crossbones+   -  Reputation: 2056

Like
0Likes
Like

Posted 28 December 2012 - 07:25 PM

Didn't know about the compiler warning, nor have I experienced it myself, but that's good to know. I always went with while(true) because for(;;) didn't come naturally to me, but I'll probably switch it up to for(;;) now.

#5 Dan Mayor   Crossbones+   -  Reputation: 1713

Like
0Likes
Like

Posted 28 December 2012 - 08:25 PM

I don't believe there's any performance difference between any flavors of the infinite loops but my personal preference is always to use a while(someValue == true).  This allows for the loop to be cancelled from within itself or from outside of the loop in say another thread.


Digivance Game Studios Founder:

Dan Mayor - Dan@Digivance.com
 www.Digivance.com


#6 return0   Members   -  Reputation: 444

Like
0Likes
Like

Posted 28 December 2012 - 09:40 PM

Threads... be careful with this.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS