complicated if statements

As I can read in the Reference section, you can have boolean operators in if statements.
But can you combine && and ||?
It would me nice, if this information would be added in the Reference section.

Of course! For example, to calculate whether a year is a leap year or not, you can use:

int leapyear(int year)
{
   if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
      return 1;  // yep, it's a leap year
   else
      return 0;
}

While many algorithms return true or false rather than 1 or 0, returning 1 or 0 lets you do something like:

daysInFebruary = 28 + leapyear(2014);

Anyway, you can mix logical AND and OR as you wish in an expression.

Ok thank you,

Here is one more simple example:

int x
loop()
{
 if (x == 0 || x < 5 && x >2)
  {
       //do something...
  }

}

Will it do something when:
x is 0 or between 2-5
or if x is between 2-5

Which means: Where are the brackets?

if (**(**x == 0 || x < 5 )&& x >2)

or if (x == 0 || (x < 5 && x >2))

The position of the "brackets" will depend on what is known as "operator precedence", in other words the language defines what order to perform the tests. You can look this up but really you should force the issue by inserting the () yourself so there is no ambiguity.

EDIT: Actually in this example I think the tests are simply performed left to right, there are no virtual brackets, if you needed one of the bracketed examples you would have to add the () yourself.


Rob

Ok, thank You.
Now that I know I can use brackets, everything seems easy.

Not only that you can use brackets, you absolutely should use them in such cases, even where no brackets would work just as well.
You will avoid some hard to track bugs in similar situations where you have to use them but forgot.