I understand that bool means true and false.
If I was doing a while loop...

while(!GAMEOVER)
do all this...
GAMEOVER = 1 or TRUE (loop exits)

IS the above correct? And is there any other ways bools are used to help reduce clutter?

Thanks,
Derek

Recommended Answers

All 4 Replies

You'll have to make sure you set GAMEOVER to false before you start the loop.

Also, the loop doesn't stop as soon as game over is set to true. For example

while(!gameover)
{
//some stuff

gameover = true;

//more stuff

}

In that example, more stuff will be run even after gameover is set to true, it has to get to the end of the loop to then go to the beginning of the loop and check the condition.

Hope that helps,

David

while (!gameover) /*sets it to false right?  or do i have to GAMEOVER = FALSE instead of !gameover?*/

Clears up a little smog, thanks
Just put gameover = true at end of loop and it will work like I want it.

No no, while(!gameover) does NOT set game over to false. It is saying "while gameover is equal to false". This is CHECKING its value, not SETTING it. You could exactly equivallently write while(gameover==false) . Note the double '=', this is c++ for "comparison".

DO NOT do while(gameover=false) . This DOES set gameover to false and this will DEFINITELY not work as you expect.

David

Ah yes double ='s, well thanks for the tid bits.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.