Alternate way to toggle a bool

Instead of writing code like:

bool x

if(x = true)
{
    x == false
}
else
{
    x == true
}

you can just write:

bool x

x = !x

!false. It’s funny because it’s true.

2 Likes

!I hate that joke.

1 Like

I saw that you did there :wink:

you could rewrite the whole thing as:

isAnsweringQuestion = !isAnsweringQuestion;
timerValue = isAnsweringQuestion ? timeToCompleteQuestion : timeToShowCorrectAnswer;

Privacy & Terms