for循环的中间部分的目的

Got*_*irl 2 c

for(i = 0; str[i]; ++i)
    ++count[str[i]];

// Change count[i] so that count[i] now contains actual position of
// this character in output array
for (i = 1; i <= RANGE; ++i)
    count[i] += count[i-1];

// Build the output character array
for (i = 0; str[i]; ++i)
{
    output[count[str[i]]-1] = str[i];
    --count[str[i]];
}
Run Code Online (Sandbox Code Playgroud)

通常,for循环的中间部分有一些比较,但for这里的第一个循环只有一个表达式.你能告诉我那是什么意思吗?

Dan*_*Dan 5

在C中,任何表达式都可以评估为"真值".在这种情况下,我们正在检查是否str[i]真实.如果是'\0',那么它是假的并且循环结束 - 这样我们可以在找到字符串的结尾后离开循环.任何其他字符值都被视为true,循环继续.