Pages: 1 ... 3 4 [5]   Go Down
Author Topic: VirtualWire  (Read 3178 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 338
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

True or false is different from HIGH or LOW right ?

i
Code:
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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 50331
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 338
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 50331
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 338
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok. I think is like this

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

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

Am I correct ?

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 50331
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 338
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you give me some simple example to illustrate that ?

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 50331
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can you give me some simple example to illustrate that ?
Can you learn to ask better questions? To illustrate what?
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 338
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Illustrate the difference between boolean variable and non-boolean variable smiley-grin
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 50331
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Illustrate the difference between boolean variable and non-boolean variable
Code:
boolean dense = false;
if(!dense)
{
   byte IQ = 14;
   byte min = 100;
   if(IQ > min)
   {
      // Smart enough
   }
   else
      dense = true;
}
Logged

Pages: 1 ... 3 4 [5]   Go Up
Jump to: