fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. std::vector<int> myvect {1, 2, 3, 4};
  6.  
  7. int main() {
  8.  
  9. int breakCount = 20;
  10. int counter = 0;
  11.  
  12. for( auto it = myvect.begin(); ; ++it ){
  13. if( it == myvect.end() ) it = myvect.begin();
  14.  
  15. cout << *it;
  16.  
  17. if(++counter == breakCount) break;
  18.  
  19. cout << ", ";
  20. }
  21.  
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4