其中while(n):


n是bool型变量时,就是代表n为true时运行循环, n是int型时,就是代表不为0时运行循环 n为表达式,就代表表达式成立时运行循环
下面是一个测试例子:
#include<iostream>
using namespace std;
int main()
{
 int n;
 scanf("%d",&n);
 while(n)
 {cout<<n<<endl;
 n--;}
     return 0;
 
}
while(n--)的原型是while(n&&n=n-1)
所以它的使用及可参照while(n)只是加了一个条件!
测试例子:
#include<iostream>
using namespace std;
int main()
{
 int n;
 scanf("%d",&n);
 while(n--)
 cout<<n<<endl;
     return 0;
 
}
此外if(n)也是一个道理!!

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-11-10
  • 2022-12-23
  • 2021-09-13
  • 2021-05-03
  • 2021-12-27
  • 2021-11-24
猜你喜欢
相关资源
相似解决方案