【小练习】循环、递归与概率:for循环
1.练习代码
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int x=10;
int y=10;
int i;
for (i=0; x>8; y=i++)
{
printf("%d, %d, ", x--, y);
}
return 0;
}
2.关键点分析
2.1处理过程
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int x=10;
int y=10;
int i;
for (i=0; x>8; y=i++)
{
//第一轮循环体执行前:i=0,x=10,y=10
//第二轮循环体执行前:i=1,x=9,y=0
//第三轮循环体执行前:i=2,x=8,y=1,不符合循环判断,跳出循环
printf("%d, %d, ", x--, y);
//第一轮循环体结束后:i=0,x=9,y=10
//第二轮循环体结束后:i=1,x=8,y=0
}
return 0;
}