Go Down

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

Vincent19

#60
Jan 26, 2013, 03:32 pm
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

#61
Jan 26, 2013, 03:49 pm
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

#62
Jan 26, 2013, 04:26 pm
what's the difference between boolean variable and non-boolean ? AND OR ?

PaulS

#63
Jan 26, 2013, 04:49 pm
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

#64
Jan 26, 2013, 04:59 pm
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

#65
Jan 26, 2013, 05:10 pm
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

#66
Jan 26, 2013, 05:11 pm
Can you give me some simple example to illustrate that ?

Thanks

PaulS

#67
Jan 26, 2013, 05:19 pm
Quote
Can you give me some simple example to illustrate that ?

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

Vincent19

#68
Jan 26, 2013, 05:21 pm
Illustrate the difference between boolean variable and non-boolean variable

PaulS

#69
Jan 26, 2013, 05:24 pm
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

Please enter a valid email to subscribe