True or False
October 04, 2008 01:41:16 Last update: October 04, 2008 02:16:22
Java requires the expression to be type
boolean. There are only two possible values for a
false. Using any other data type in a boolean context (such as an
ifcondition) is an error.
C# supports a strict boolean type,
bool. Statements that take conditions, such as
if, require an expression of a
C# disallows this "integer meaning true or false" approach on the grounds that forcing programmers to use expressions that return exactly
boolcan prevent certain types of programming mistakes such as
if (a = b)(use of
A scalar value is interpreted as TRUE in the Boolean sense if it is not the null string or the number 0 (or its string equivalent, "0").
In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false:
None, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.
Ruby has a simple definition of truth. Any value that is not
nilor the constant
The number zero is not interpreted as a false value. Neither is a zero-length string.
When converting to boolean, the following values are considered
- the boolean
- the integer 0 (zero)
- the float 0.0 (zero)
- the empty string, and the string "0"
- an array with zero elements
- an object with zero member variables (PHP 4 only)
- the special type
NULL(including unset variables)
- SimpleXML objects created from empty tags
Every other value is considered
TRUE(including any resource).
- the boolean