Go Down

Topic: VirtualWire (Read 3 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

Go Up