How to break an infinite loop
-
If i made a program which prints on the screen " Mike " infinite times without stop . how can i define a certain key if i pressed the program stop printing ? ====== I use ' getch() ' method but the program had to stop and check my entry and this isn't my question here.
-
If i made a program which prints on the screen " Mike " infinite times without stop . how can i define a certain key if i pressed the program stop printing ? ====== I use ' getch() ' method but the program had to stop and check my entry and this isn't my question here.
You have to include some code inside the loop to recognise the keystroke or some other event to break out of the loop. If you add a
getch
then that would pause the loop until the keystroke is delivered. To get round this you can put that code in a separate thread and set a flag for the loop to check. You could also use _kbhit[^], although it has limitations. -
If i made a program which prints on the screen " Mike " infinite times without stop . how can i define a certain key if i pressed the program stop printing ? ====== I use ' getch() ' method but the program had to stop and check my entry and this isn't my question here.