+ 1

In conditional statements or while loops:

For example, hasWon is a boolen that is set to false, "If (!hasWon)" should be thesame as "if (hasWon !=false)" But only the first one works, The second one is more understandable to me but it doesn't work,........ Please help..........

4th Nov 2020, 11:25 PM
IFECHUKWU
IFECHUKWU - avatar
4 Respuestas
+ 1
The way you wrote it they are not same. But you can write hasWon==false if you prefer. In a professional setting you might have to follow conventions, but for your own do as you like
4th Nov 2020, 11:32 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
If you have boolean hasWon=false; Then, If (!hasWon) -> this will result to True because you're negating False. And (hasWon !=false) ->will result to false because it wil be (false != false)
5th Nov 2020, 3:32 AM
Azalea
0
Thanks alot , I understand better now,
7th Nov 2020, 1:55 AM
IFECHUKWU
IFECHUKWU - avatar
0
I feel the first should be more understandable 😊, but anyways; the two are not the same. Since hasWon = false, !false (not false) will result to true, vice versa. If you say hasWon == false you'll get true as the result because the two sides of the equality are the same (false == false) But when you say hasWon != false you'll get false because false (hasWon) is not different from false.
9th Nov 2020, 6:56 PM
Ene-une Reuben Ochedi
Ene-une Reuben Ochedi - avatar