C++ Pause

May 27, 2010 at 11:52pm
Hello.

I am trying to understand a C++ snake program I encounted on the net and can't seem to understand the following line:
for (int i=0;i<(speed*pause_length);i++) int j=1+i

I understand what the loop is doing, but I don't understand how it controls the speed of the game. pause_length is a const variable set to 500000 and speed is set at 80. How does this control the speed of the game?

Thanks
May 28, 2010 at 12:01am
It is an old technique to delay by simply doing a loop for a while. This worked on older computers (like the 8086) where it was slow enough for such things to make sense. These days, it does not.

Instead, use an OS-specific delay function, such as the following
http://www.cplusplus.com/forum/unices/10491/#msg49054

For that you only really need one variable -- the number of milliseconds to delay (the "speed").

Hope this helps.
May 28, 2010 at 2:31am
What header file should I include? I am using Dev C++?
May 28, 2010 at 12:50pm
Simply copy and paste the code I gave you.
Topic archived. No new replies allowed.