Difference between revisions of "And"
Jump to navigation
Jump to search
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
A logical (Boolean) operator that returns [[True]] only if both of its operands are true. Logical operators are used in logical (Boolean) expressions that operate with true/false values. | A logical (Boolean) operator that returns [[True]] only if both of its operands are true. Logical operators are used in logical (Boolean) expressions that operate with true/false values. | ||
− | + | == Usage == | |
<syntaxhighlight>E1 And E2</syntaxhighlight> | <syntaxhighlight>E1 And E2</syntaxhighlight> | ||
− | Where: | + | Where: |
− | |||
− | |||
− | |||
− | + | :'''E'''- true/false expressions. | |
+ | == Notes == | ||
+ | * If one of the true/false expressions evaluates to false, the whole expression is evaluated as false due to the '''and''' logical operator. For example: | ||
+ | :<syntaxhighlight>(10 > 1) and (10 > 20)</syntaxhighlight> | ||
+ | :Will evaluate to [[False]] since the second expression is not true, even though the first expression (10 > 1) is true. | ||
+ | * The whole expression is evaluated as true if, and '''only if''', all true/false expressions are true. For example: | ||
+ | :<syntaxhighlight>(10 > 1) and (100 < 2000) and (1 = 1)</syntaxhighlight> | ||
+ | :Will evaluate to [[True]] since all individual expressions are indeed true. | ||
+ | * Also see the logical expression [[Or]] for true/false evaluations. | ||
+ | |||
+ | == Examples == | ||
+ | <syntaxhighlight>2 = 1 And 2 = 2</syntaxhighlight> | ||
+ | Will return a value of False. | ||
+ | <syntaxhighlight>True And True And True</syntaxhighlight> | ||
+ | Will return a value of True. | ||
[[Category:Comparisons and Loops]] | [[Category:Comparisons and Loops]] |
Latest revision as of 10:14, 19 February 2012
A logical (Boolean) operator that returns True only if both of its operands are true. Logical operators are used in logical (Boolean) expressions that operate with true/false values.
Usage
E1 And E2
Where:
- E- true/false expressions.
Notes
- If one of the true/false expressions evaluates to false, the whole expression is evaluated as false due to the and logical operator. For example:
(10 > 1) and (10 > 20)
- Will evaluate to False since the second expression is not true, even though the first expression (10 > 1) is true.
- The whole expression is evaluated as true if, and only if, all true/false expressions are true. For example:
(10 > 1) and (100 < 2000) and (1 = 1)
- Will evaluate to True since all individual expressions are indeed true.
- Also see the logical expression Or for true/false evaluations.
Examples
2 = 1 And 2 = 2
Will return a value of False.
True And True And True
Will return a value of True.