for和while语句条件中的i++和++i的用法
作者:
dandelion7
,
2024-02-21 15:09:47
,
所有人可见
,
阅读 51
(1) for语句 i++
int count=0;
for(int i=0; i<6; i++){
count++;
}
cout<<count<<endl;
(2) for语句 i++
int count=0;
for(int i=0; i<6; ++i){
count++;
}
cout<<count<<endl;
(3) for语句 i++在循环体中
int count=0;
for(int i=0; i<6; ){
count++;
i++;
}
cout<<count<<endl;
** 以上三种 count = 6。**
(1) while语句 i--
,count=6
int count=0;
int i=6;
while(i--){
count++;
}
cout<<count<<endl;
等同于
int count=0;
int i=6;
while(i){
i--;
count++;
}
i--;
cout<<count<<endl;
(2)while语句 --i
,count=5
int count=0;
int i=6;
while(--i){
count++;
}
cout<<count<<endl;
等同于
int count=0;
int i=6;
i--;
while(i){
count++;
i--;
}
cout<<count<<endl;