【发布时间】:2021-04-08 17:22:37
【问题描述】:
我想用类似于 python 的布尔值做一个 while 循环。
我想要类似的东西:
while(player1_health > 0 or player2_health > 0){
//code
}
【问题讨论】:
-
也许掌握一本 C 编程书籍是学习 C 编程语言的更快方法
标签: c
我想用类似于 python 的布尔值做一个 while 循环。
我想要类似的东西:
while(player1_health > 0 or player2_health > 0){
//code
}
【问题讨论】:
标签: c
C 中没有or 运算符,在C 中我们使用符号||,称为逻辑或运算符。
使用这个
while( (player1_health > 0) || (player2_health > 0) ) {
//code
}
更新: 看起来 C99 包括 or , and 运算符 || , &&,如果您使用的是 C99 它适用于包含头文件#include <iso646.h>
【讨论】:
#include <iso646.h>。见stackoverflow.com/questions/17365271/and-and-operator-in-c
#include <iso646.h> 中的“或”是一个宏,因此它不是语言的一部分。 C 中的“或”运算符是||。