我正在阅读代码,发现了一个 while 循环,其结构如下:
while(q--)
我知道这是一个后减运算符,但我不明白 while 循环中正在测试的条件
感谢您抽出时间,康纳
最佳答案
while
循环检查条件是否为真。
计算结果为 0 的表达式被视为 false,而任何非零表达式都被视为 true。
摘自 C Standard 的第 6.8.5 节:
4 An iteration statement causes a statement called the loop body to be executed repeatedly until the controlling expression compares equal to 0. The repetition occurs regardless of whether the loop body is entered from the iteration statement or by a jump
因此这个循环测试 q
是否非零。一旦q
减至0,循环就会退出。
关于C语言编程,while循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40476461/