I found another solution for this challenge using the exclamation mark. By coming back to the game window everything seems to work perfectly.
Can anyone explains me when using ‘else’ statement is better than the exclamation mark solution ?
In both cases we end up with four lines of code, it’s not shorter but there must be a reason What do you think ?
The approach you used would be two separate questions
As you can see, the first method is far more efficient since you are asking a single question and getting the exact same result from asking 2 questions. That’s what else statements are for, to prevent code from running when the first if statement already met the condition.
Does this mean you should always use else statements? The answer to that is, no. Using the same question analogy, sometimes you want to ask completely unrelated questions.
Using else statements:
Using two separated if statements:
It all comes down to what you are trying to achieve with your code and if the two code blocks can/should run right after the other.
In this case, since you cannot have a button down and up at the same time (unless it’s a quantic button or something weird thing like that), the better approach is to use an else statement.