Postagens

Mostrando postagens de fevereiro, 2020

Relational Operators

English: Relational Operators You can also store boolean expression for bool variables, besides "true" or "false" states. If you want to do that, you need to use relational operators. Look at the code below: bool checkNumber = 10 > 5; Which value "checkNumber" stores at this moment? In the code above, we are using one relational operator (>) to check if the value on the left is more than the value on the right. If 10 is more than 5, do you agree that this expression is a truth? If this boolean expression is a truth, the value of "checkNumber" is "true" too. But if you write: checkNumber = 2 > 514; The value from "checkNumber" is false now, because 2 is not more than 514. Returning "true" through from expression above, we can use other relational operator (<) which checks if value on the left is less than value on the right: checkNumber = 2 < 514; At this

Boolean type

English: Boolean Type Boolean variables can only store two values: true or false. As like binary logic, which these values determine how the machine will behaviour. Thinking about that, imagine that you are programming a game, you are able to use a boolean variable to check some actions about player's input. For example, when player, press space key, your hero can attack. Using boolean variable, storage "true" value for one bool type when the player press enter to attack. Now, if your game has an enemy, and if the bool variable is true, it can check if player is attacking him. bool attacking = true; And if player stops to attack, this boolean variable will store "false" value: attacking = false; With these two states, you can control the behaviours around "attacking" variable, like enemies, weapons, energy and anything that depends on this parameter in your game. Português-BR: Tipo Booleano Variáveis ​​boo