我是靠谱客的博主 友好雨,这篇文章主要介绍c++中for循环和while循环的比较,现在分享给大家,希望可以做个参考。

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循环内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部