9C. Standards for Boolean Expressions

Only use boolean operations on boolean values [Boolean op: 1-2 points]

Boolean operations (!, && and ||) should only be used on boolean values (which are known to be 0 or 1). Do not use them on integers, pointers, etc. (But see the exception in the next entry.)

Conditions should be boolean [Boolean condition: 1-2 points]

The condition in an if-statement, while-statement, for-statement, do-statement, or any other construct that performs a yes/no test should be a boolean value. It should not be a number or a pointer.

An exception is an expression that uses the ctype library, such as isdigit((unsigned) c) and isalpha((unsigned) c). Those can be used in tests as boolean values.


Do not use == true or == false [Boolean eq: 1-2 points]

An if-statement, while-statement, etc. tests whether its condition is true. Do not write something like
  if(isEmpty(x) == true)
where you redundantly ask if isEmpty(x) is true. Write
  if(isEmpty(x))
Use ! for negation. Instead of
  if(isEmpty(x) == false)
write
  if(!isEmpty(x))

Do not use if(x = y) [Assign in test: 1-3 points]

Even if it is what you intend to write, do not use an assignment as the test in an if, while, do or for statement. If you ask for warnings (which you always should), g++ will warn you about this. Heed the warning.