Boolean

Hey guys,

Can you use Boolean's with the Arduino? They compile fine but don't seem to be working for me:

In my code I Initialise my boolean like so:

boolean tagged = false;

I then to be really sure set it to false just before I enter a loop depending on it.

tagged=false;
while (tagged = false)
{
//do stuff
}

When I try it like this the while loop is skipped over, When I change the while condition to true it enters the while loop. However even if in the while loop I put tagged=false; it still won't change and the loop continues forever.

Any ideas?

Boab,

That should be:

boolean tagged = false;
while (tagged == false)
  {
  // do something
  }

The problem was that you were using '=' instead of '=='. Comparison is done with the '==' operator.

You could also change your 'while' to be more concise:while (!tagged)Regards,

-Mike

Thanks Mike, That worked Thanks for the help

Just so its clear in my mind
if I put
tagged = !tagged;

does that set tagged to false each time or does it change it to whatever it wasn't before?

If it changes it to what it wasn't before how do I set it specificly to true or false regardless of what it was previous
tagged == false; doesn't seem to work for me

tagged = !tagged; will set tagged to true if it was false, or to true if it was false.

tagged == false; is a comparison operation. tagged = false; is an assignment operation.