Click here to Skip to main content
15,911,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose, An infinite loop print an animation. This animation will stop with key pressed in keyboard or mouse movement.

C++
while(true)
{
   /*
      Animation Code
   */

  
}


Please, remember the loop does not wait for any input from user. What should I do to break this infinite loop.

Thanks.
Posted

You must check inside the loop if a key has been pressed or the mouse has been moved.

How this can be done depends on the used operating system (e.g. _kbhit with Windows).
 
Share this answer
 
You can try like this
C++
while(!kbhit())
{
  //do your work
}

if you press any key it will come out of the loop
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900