Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TheMatrixXXX

main loop

This topic is 5887 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

Advertisement
for (; ; ) { }

It's basically the same as "while (true) {}", but this way you avoid one futile comparison.


theNestruo

Syntax error in 2410
Ok

[edited by - theNestruo on May 4, 2002 1:55:01 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Oluseyi
And replace it with another. Brilliant.



No, you don''t, actually.

for(;, even in debug builds with popular comparisons, is implemented as a straight jump. It doesn''t have *anything* to compare to, so it doesn''t bother with any comparison. while(true) will laboriously compare true to true every iteration. Optmized builds will typically remove the comparison, but for(; -- by virtue of having nothing to compare -- won''t make it an issue. If you said for(;true, perhaps it would put the test back in, but I''m not sure that anyone would bother.

Share this post


Link to post
Share on other sites
All a bit of a moot point since any half-way decent compiler will produce the same code, and more to the point, you wouldnt want to do either of them anyway.

Or would you...? Maybe theres a couple of things you could do in certain situations with ''break'' to exit the loop but not exactly clear coding i''ll bet.

Share this post


Link to post
Share on other sites
hi

thx but the methods with while(true) or for(; i know already

but it doesn´t work in my ogl program

when i compile i get an acces violation but i don´t know why


ok more details:

i have 4 forms with ogl windows and i need in every form a main loop because at the moment i have only timers for testing ( i know that is shit but i didn´t want to use the app idle time)

thx
--=[[TheMatrixXXX]]=--

Share this post


Link to post
Share on other sites
It''s a strange question to begin with. "Can anyone tell me how to create a main loop" ...? A main loop is no different from any other loop. It''s a loop. You iterate things. As for how to construct it, you just have to figure out what you want to iterate (respond to input, execute AI and game physics, update graphics and so forth) and put it all in there. (As for why you would bother to specify which compiler you use, I have no idea ...)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!