nus-cs2113-AY2122S2 / forum

3 stars 2 forks source link

If Else Statements #38

Closed siewyangzhi closed 2 years ago

siewyangzhi commented 2 years ago

Hi, it was mentioned that when we are checking to see if a variable is value A or Value B, we shouldn't do if (variable == value A) { //Do something }else{ // Assuming that the variable is value B and do something. } I get that the rationale for doing this is because the variable can hold more than 2 values thus we cant assume that if it isnt value A, it would be value B.

image

However, for my case above , i am checking the value of a boolean thus can i use the if statement to check if the boolean is true and for the else statement, i would assume it is false since it can only take on two values.

okkhoy commented 2 years ago

You have answered your own question -- When do you need an explicit else? So for boolean, what you have is correct.

siewyangzhi commented 2 years ago

I see thank you