最近我在下面的示例中在 C 中看到了这个 while 循环条件,但我不知道 while 条件的真正含义以及编译器如何知道它何时完成。有人可以向我解释吗?
这就是我认为的意思:while 循环遍历 char 数组,直到数组结束,因为没有别的东西,然后 while 循环结束,还是我错了?我尝试使用相同的 while 循环,但使用另一种语言(例如 Go),但是编译器抛出错误,说我不能使用非布尔值。
// C program to demonstrate
// example of tolower() function.
#include <ctype.h>
#include <stdio.h>
int main()
{
int j = 0;
char str[] = "GEEKSFORGEEKS\n";
// Character to be converted to lowercase
char ch = 'G';
// convert ch to lowercase using toLower()
char ch;
while (str[j]) { // <- this part, how is this a condition?
ch = str[j];
// convert ch to lowercase using toLower()
putchar(tolower(ch));
j++;
}
return 0;
}