-->
和 <--
运算符
使用方法如下:
#include <iostream>
using namespace std;
int main()
{
int i = 10;
while(i --> 0) cout << i;
return 0;
}
输出 9 8 7 6 5 4 3 2 1 0
#include <iostream>
using namespace std;
int main()
{
int i = 10;
while(0 <-- i) cout << i;
return 0;
}
输出 9 8 7 6 5 4 3 2 1
#include <iostream>
using namespace std;
int main()
{
int i = 10;
do cout << i << ' ';
while (i --> 0);
return 0;
}
输出 10 9 8 7 6 5 4 3 2 1 0
#include <iostream>
using namespace std;
int main()
{
int i = 10;
do cout << i << ' ';
while (0 <-- i);
return 0;
}
输出 10 9 8 7 6 5 4 3 2 1
注意,i
不能是常数!!!
其实,就是 i-- > 0
0 < --i
ok,原来是一个用的前缀,一个用的后缀。