【问题标题】:How do i add boolean in c? [closed]如何在c中添加布尔值? [关闭]
【发布时间】:2021-04-08 17:22:37
【问题描述】:

我想用类似于 python 的布尔值做一个 while 循环。

我想要类似的东西:

while(player1_health > 0 or player2_health > 0){
    //code
}

【问题讨论】:

标签: c


【解决方案1】:

C 中没有or 运算符,在C 中我们使用符号||,称为逻辑或运算符。

使用这个

while( (player1_health > 0) || (player2_health > 0) ) {
    //code
}

更新: 看起来 C99 包括 orand 运算符 ||&&,如果您使用的是 C99 它适用于包含头文件#include <iso646.h>

【讨论】:

  • 如果你是#include <iso646.h>。见stackoverflow.com/questions/17365271/and-and-operator-in-c
  • 谢谢@JohnZwinck,我学到了一些新东西,更新了帖子,可以吗?
  • #include <iso646.h> 中的“或”是一个宏,因此它不是语言的一部分。 C 中的“或”运算符是||
猜你喜欢
  • 1970-01-01
  • 2021-04-04
  • 2017-09-05
  • 2018-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-24
  • 1970-01-01
相关资源
最近更新 更多