当我们想输出好几行重复内容时可以使用嵌套循环。
#include<iostream>
using namespace std;
int main()
{
//使用嵌套循环语句在黑窗口中
for (int SHU = 0; SHU <= 10; SHU++)
{
for (int shu = 0; shu <= 10; shu++)
{
cout << "* ";//此处不能转行,要在一行输出十个*
}
cout << endl;
//此处是输出完十个*后换到下一行,并是把 按任意键继续 换到下一行
}
system("pause");
return 0;
}
除了for循环其他任何循环语句都可以互相嵌套。