main loop

Started by
13 comments, last by TheMatrixXXX 21 years, 11 months ago
hi all can anyone tell me how to create a main loop in borland c++ builder 5.0 ? thx for help --=[[TheMatrixXXX]]=--
--=[[TheMatrixXXX]]=--
Advertisement
while (true) { }
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]
theNestruoSyntax error in 2410Ok
quote:Original post by theNestruo
It''s basically the same as "while (true) {}", but this way you avoid one futile comparison.

And replace it with another. Brilliant.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
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.
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/
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.
You know, after posting that I thought about the possibility that for( ; ; ) would evaluate to a straight jump, but decided to leave my comments in and take the flak.

Thanks for clearing that up.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
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]]=--
--=[[TheMatrixXXX]]=--
so did anyone really answer the question?
-Scott
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 ...)

This topic is closed to new replies.

Advertisement