One common problem is to know how your function behaves but not knowing how to formalize your statement as an expression of boolean operators. Here is what you should know before we get into details.
Logical Operators
Imagine that we have two buttons with two states each so that we have A(on/off) and B(on/off). Among the two we have four different states, that is A on and B off, A on and B on, A off and B on and A off and B off. Now, to start using a more formal language A and B are BOTH on when A AND B are on, and both A and B are off when A AND B are off. If we were to connect the two buttons in line to a cable then both A and B would have to be on for the current to pass and in any other case there wouldn't be current at the end of the line. On the other hand if we were to connect them in parallel then either A OR B should be on for the current to pass and iff A are B are both off there won't be current at the end of the line.
---A---B----> C---- [BA]----> D
line serial
Truth Tables
Let us now imagine that a light C is connected to those two cables and we need to know when the light is going to go on and when off. We construct a table, called a truth table as such:
A B A&B A||B (A'&B')' !A||B case
0 0 0 0 0 0 1
0 1 0 1 1 1 2
1 0 0 1 1 0 3
1 1 1 1 0 1 4
You might have noticed that the first two columns count in binary, which is the orderly way to count. Let us now forget about the table and return to the example with the light: The light C will light up in case 4, when A and B are on and it may be expressed that if A is on and B is on then C is on. The light D, with the serial connection will light up in cases 2, 3 and 4, when either of the buttons are pressed.
The 5th column expresses a more composite probability which is the exclusive junction, or the probability that only one of the two is on and apparently requires a complicated setup. Generally, the possibility of A being on is symbolized as A, the possibility of A being off as !A and the complementary of a possibility as A', that is, if we were to put an inverter to A so that when A would be off the rest of the circuit would be on (note that (!A)' == A). With that in mind the 5th column can be read as the complimentary of the possibility of the junction of the complementary possibilities of A and B.
The sixth column represents again the light named D, from the previous paragraph, given that A is damaged, it basically is equal to the second column of having only B as a button.
Putting it all together
Now let us suppose that we have a problem that should be programmed using an if statement and should handle 4 possibilities, of which only one should trigger an event. Consulting the truth table of the previous section we see the 3rd column describing the situation. We then may create two variables to describe the condition and continue as follows:
if (A&&B) {something}
else {something else}
If the problem we were dealing with demanded the encoding of a probability of 3 out of 16 then a more complicated truth table would be required, particularly one with three variables. Then we would populate all the necessary columns with various possibilities like (A&&B)||(!C) or (A&&!B)&&C' and then when we would have found a column with only 3 1's among 13 0's we would have completed our research and would be ready to start coding!