True or False 

Joined:
04/09/2007
Posts:
775

October 04, 2008 01:41:16    Last update: October 04, 2008 02:16:22
  1. Java
    Java requires the expression to be type boolean. There are only two possible values for a boolean: true or false. Using any other data type in a boolean context (such as an if condition) is an error.

  2. C#
    C# supports a strict boolean type, bool. Statements that take conditions, such as while and if, require an expression of a boolean type.
    C# disallows this "integer meaning true or false" approach on the grounds that forcing programmers to use expressions that return exactly bool can prevent certain types of programming mistakes such as if (a = b) (use of = instead of ==).

  3. Perl
    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").

  4. Python
    In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: 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.

  5. Ruby
    Ruby has a simple definition of truth. Any value that is not nil or the constant false is true.
    The number zero is not interpreted as a false value. Neither is a zero-length string.

  6. PHP
    When converting to boolean, the following values are considered FALSE:
    • the boolean FALSE itself
    • 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).
Share |
| Comment  | Tags