1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
int main()
{
// 初始化变量i = 0; 当 i < 5 时进入循环; 每次循环后i++
for (int i = 0; i < 5; i++)
{
std::cout << "for {} run..." << std::endl;
}
int i = 0;
bool condition = true;
for (; condition; ) // 不指定初始化变量和增量并且条件为true,则是无限循环
{
std::cout << "for {} run ..." << std::endl;
i++;
if (!(i < 5))
condition = false;
}
}
|