(row > 0 && row < 4 && col > 0 && col < 4)
is itself a boolean (true or false).
We can break it down as boolean && boolean && boolean && boolean
as <
and >
operators return booleans. Likewise, a boolean and a boolean is a boolean, therefore the entire expression is a boolean and can be returned as such.
You can think about it as such:
- For the row, you have a number, so you can say "how many" or "which number". Same for the column.
- For the comparisons, you can ask: If x and y are numbers, then is x < y? The answers possible are
true
orfalse
. Hence boolean. - For
&&
,||
, or!
, you can ask yourself: "If a and b are statements (true or false), then "a and b are both true" is either true or false. Same for "or", or "a is not true". The results are true and false.
Now you can look at the if, and read it as "if foo is true, then return false. Otherwise, return true". This clearly simplifies to "return the opposite of foo" or, "return not foo".