True or False
October 04, 2008 01:41:16 Last update: October 04, 2008 02:16:22
- Java
Java requires the expression to be typeboolean. There are only two possible values for aboolean:trueorfalse. Using any other data type in a boolean context (such as anifcondition) is an error.
- C#
C# supports a strict boolean type,bool. Statements that take conditions, such aswhileandif, require an expression of abooleantype.
C# disallows this "integer meaning true or false" approach on the grounds that forcing programmers to use expressions that return exactlyboolcan prevent certain types of programming mistakes such asif (a = b)(use of=instead of==).
- 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").
- 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.
- Ruby
Ruby has a simple definition of truth. Any value that is notnilor the constantfalseis true.
The number zero is not interpreted as a false value. Neither is a zero-length string.
- PHP
When converting to boolean, the following values are consideredFALSE:- the boolean
FALSEitself
- 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 consideredTRUE(including any resource). - the boolean