Kind of sad that the simplified NOT operator wasn't shown as an extra example

It might just be cause I come from other language backgrounds but it seems like a missed opportunity not to include an extra tip about using the simplified NOT (!) operator as a follow up bit of info:

while(!WindowShouldClose()) {
    BeginDrawing();
    ClearBackground(RED);
    EndDrawing();
}

For anyone who reads this and is confused what is going on here a ! before any value inverts it’s normal boolean value so !true would actually equal false and !false would equal true same is true for any other math operators or functions that return boolean if you want the inverse answer. makes writing if and while statements much cleaner than WindowShouldClose() == false.

sorry for the detour, back to your lessons :slight_smile:

5 Likes

This is the way I did it also and was going to post the option as an alternative, but I see you beat me to it! :slightly_smiling_face:

1 Like

This is a common thing when teaching programming to beginners. It’s better to show explicitly what is going on rather then the simplified, sometimes more implicit way.

“while (WindowShouldClose() == false);” does not work.
“while (!WindowShouldClose())” worked perfectly fine.
All I did was backspace " == false" and add the “!” and it worked.
Why doesn’t it seem to work the other way for me?

The semi-colon in while (WindowShouldClose() == false); is the reason why it didn’t work. semi-colons are used to end a statement in c++, so putting one at the declaration of an if-statement or loop will cause undesired behavior if not a compilation error.

1 Like

Privacy & Terms