1.continue语句,1至20内奇数累加和
#include<iostream>
using namespace std;
void main(){ int i=0;
int sum=0;
while(i<20){
i++;
if(i%2==0)
continue;
else
sum+=i;
cout<<"当前i的值为"<<i<<" sum的值为"<<sum<<endl;
}
system("pause");
}
2.break语句,1至20累加和
#include<iostream>
using namespace std;
void main(){ int i=0;
int sum=0;
while(i<50){
i++;
if(i==21)
break;
else
sum+=i;
cout<<"当前i的值为"<<i<<" sum的值为"<<sum<<endl;
}
system("pause");
}