Boolean Expressions
You can also combine boolean statements. For example, the player is alive in a game while his health_value > 0
AND stamina_value > 0
. You can write an expression like this in C++ using the and
operator:
main.cpp
Let's look at the and
operator in greater detail. It returns true
if both statements are true. If at least one statement is false
, the and
operator will return false
.
And if you want the player to have health_value > 0
OR stamina_value > 0
you can use the or
operator.
main.cpp
To summarize, here is a table with the results of applying those operators to statements.
Initial bool1 | Initial bool2 | bool1 and bool2 | bool1 or bool2 |
---|---|---|---|
true | true | true | true |
true | false | false | true |
false | true | false | true |
false | false | false | false |
¿Todo estuvo claro?
Contenido del Curso
C++ Data Types
2. Numerical Data Types
4. Other Data Types and Concepts
C++ Data Types
Boolean Expressions
You can also combine boolean statements. For example, the player is alive in a game while his health_value > 0
AND stamina_value > 0
. You can write an expression like this in C++ using the and
operator:
main.cpp
Let's look at the and
operator in greater detail. It returns true
if both statements are true. If at least one statement is false
, the and
operator will return false
.
And if you want the player to have health_value > 0
OR stamina_value > 0
you can use the or
operator.
main.cpp
To summarize, here is a table with the results of applying those operators to statements.
Initial bool1 | Initial bool2 | bool1 and bool2 | bool1 or bool2 |
---|---|---|---|
true | true | true | true |
true | false | false | true |
false | true | false | true |
false | false | false | false |
¿Todo estuvo claro?