0

how to break a running infinite loop without using Ctrl+c ?

e.g.

#include <iostream>    
int main()
{
     int x = 0;
     for(;;)
         cout << x;
}

I want the loop to keep going but break it using a key at anytime.

Using getch () and break statement this way will make the loop stop and wait for a response.

    #include <iostream>
int main()
{
     int x = 0;
     for(;;)
     {
         cout << x;
         if(getch()=='n')
                break;
     }

0 Answers0