--n,n--在while语句中的用法

#include
using namespace std;
int main()
{


int count=0,n=6;
while(--n)
{
count++;
n--;
}
cout<<count;

}

注意--n和n--的区别,--n是n先减1再判断,n--是先判断在减少1.

while判断取值为 5,3,1,-1,-3.。。。。。。。。。。。。永远取不到0,不为0,就为真,所以这程序是死循环。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章