Break an infinite loop : break « Operators statements « C++ Tutorial






#include <iostream> 
using namespace std; 
 
int main() 
{ 
  int t, count;  
 
  for(t=0; t<10; t++) { 
    count = 1; 
    for(;;) { 
      cout << count << ' '; 
      count++; 
      if(count==10) break; 
    }  
    cout << '\n'; 
  } 
 
  return 0; 
}
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9








3.18.break
3.18.1.Break a for loop
3.18.2.Break an infinite loop
3.18.3.Break from while
3.18.4.Demonstrating a Forever Loop