Go Down

Topic: VirtualWire (Read 3786 times) previous topic - next topic

Vincent19

True or false is different from HIGH or LOW right ?

i
Code: [Select]
f (variable==true)
{
Do this
}

if (variable == false)
{
Do that
}

if (variable == HIGH)
{
Do this
}

if (variable ==LOW)
{ Do that}

Correct me if I am wrong

PaulS

Quote
True or false is different from HIGH or LOW right ?

Yes.

The if(variable == true) test is silly. If variable is true, the test evaluates to true == true, which is true. So, the initial test could simply have been if(variable). That is the convention for testing boolean variables. To do something when the variable contains false, you use if(!variable) (if not true).

For non-boolean variables, the 3rd and 4th examples are correct.

Vincent19

what's the difference between boolean variable and non-boolean ? AND OR ?

PaulS

Quote
what's the difference between boolean variable and non-boolean ?

One is a boolean variable. The other is not. It might be an int, a float, a double, a long, a char, a byte, a long long, etc.

Vincent19

Ok. I think is like this

Code: [Select]
If (x>y) --> this is example of boolean variable which will return either true or false.

Code: [Select]
If (variable==HIGH) --> This is non boolean variable..

Am I correct ?

Thanks

PaulS

Quote
--> this is example of boolean variable which will return either true or false.

No, that is an example of two int (I'm assuming) values being compared. Comparing boolean variables using > doesn't make sense.

Quote
--> This is non boolean variable..

The statement itself does not provide enough information to answer the question. What is the type of variable? That is what determines how to write the statement. It doesn't make sense to compare a boolean variable (containing true or false) to HIGH or LOW. So, it appears that the statement does not involve a boolean variable.

Vincent19

Can you give me some simple example to illustrate that ?

Thanks

PaulS

Quote
Can you give me some simple example to illustrate that ?

Can you learn to ask better questions? To illustrate what?

Vincent19

Illustrate the difference between boolean variable and non-boolean variable :D

PaulS

Quote
Illustrate the difference between boolean variable and non-boolean variable

Code: [Select]
boolean dense = false;
if(!dense)
{
   byte IQ = 14;
   byte min = 100;
   if(IQ > min)
   {
      // Smart enough
   }
   else
      dense = true;
}

Go Up