在一个for循环体中,我需要用到两个变量。比如说:
for(int n=0;int f=n+1&&f<5;++n)
cout<<f;
就像这种形式。我在vs2015上一跑就死循环了(。-_-。) 那这种情况下我应该如何改写代码让它能成功运行呢?
谢谢。
伊谢尔伦2017-04-17 13:45:07
First look at your code
for(int n=0;int f=n+1&&f<5;++n)
cout<<f;
The intermediate loop termination condition is int f=n+1&&f<5
, && has a higher priority, so it is equivalent to int f=(n+1&&f<5). Obviously, f is always 1. If you know the reason, you can see how to change it. You got it.
黄舟2017-04-17 13:45:07
Thank you for your generous advice, I have found the answer. The reason is that I put an assignment statement where the conditional judgment is.
The Android client will not fix the problem, so I would like to thank you all here