How much flour do you have? 6 How much sugar do you have? 4 Enough for cookies!
When execution got to the if
statement, it found that
flour >= 4 --- true, because 6 >= 4
and
sugar >= 2 --- true, because 4 >= 2
Since both sides were true, the two part question gave us true.
The and
operator && is used to
insist that there is a true on both sides:
this side must be true && this side must be true
If both sides are true, the entire expression is true. If either side (or both) are false, the entire expression is false. "&&" is called a logical operator because it combines two true/false values into a single true/false value
A compact way of saying what && does is:
The and-operator is used when every requirement is must be met.