c++中如何控制循环

如何中途干涉循环的运行,例如我想在for循环的第五次时输出一个endl(换行)应该怎么办

你题目的解答代码如下:

#include<iostream>
using namespace std;

int main()
{
    int i;
    for (i = 1; i <= 10; i++)
    {
        cout << i << " ";
        if (i==5)
            cout << endl;
    }
    return 0;
}

img

如有帮助,望采纳!谢谢!

for(int i =1;i<100;i++)
{
if(i == 5) cout << endl;
}


for(i=1;i<10;i++){
  if(i==5){
      cout<<endl;
  }
}