for和while的选择
1)当已经确定了循环次数时,建议使用for
2)其他情况,可以使用for ,也可以使用while, 建议使用while
使用for循环实现1+2+3+…100 = ?
#include
#include <Windows.h>
#include
using namespace std;
int main(void){
for(int i =1;i<=100;i++){
s=s+i
}
cout<<s<<endl;
system(“pause”);
return 0;
}
最后
以上就是友好雨最近收集整理的关于c++中for循环和while循环的比较的全部内容,更多相关c++中for循环和while循环内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复