循环语句包括for循环和while循环。其中两个可以互相转换。(个人更推荐while循环)
while循环
最简单的while(1)即为无限循环
#include <iostream>
using namespace std;
int main(){
while(1){
//其中在计算机中 1 即为真, 0 即为假。真就是做的意思,假就是不做的意思。
printf("hello world\n");
}
return 0;
}
输出为
hello world
hello world
hello world
hello world
…
然后还可以这样操作。
#include <iostream>
using namespace std;
int main(){
int i=0;
while(i<3){
printf