freeCodeCamp/guide/chinese/logic/logical-operators/index.md

46 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Logical Operators
localeTitle: 逻辑运算符
---
## 逻辑运算符
**AND&&**
如果A和B都为True&& B返回True。如果A或B或两者都为False则A && B为False。
| A | B |和AB| | --- | --- | --- | | F | t | f | | F | f | f | | T | t | t | | T | f | t |
**或(||**
如果A或B或A和B都是则A || B返回True。如果A和B都为False则仅返回False。
| A | B | ORAB| | --- | --- | --- | | F | t | t | | F | f | f | | T | t | t | | T | f | t |
**不(!)**
返回相反的值。防爆。如果A为真那么A为假如果A为假那么A为真。这是唯一只对一个输入起作用的逻辑运算符这使它成为一元运算符。
| A | B | NOTA| NOTB | --- | --- | --- | --- | | F | t | t | f | | F | f | t | t | | T | t | f | f | | T | f | f | t |
**异或“eXclusive或”**
被称为**独家或** 。与OR类似但如果A和B都为真则返回False。也就是说如果A或B中只有一个为True则XOR返回true。
| A | B | XORAB| | --- | --- | --- | | F | t | t | | F | f | f | | T | t | f | | T | f | t |
**含义A - > B**
读为“如果A则B”或“A暗示B”。 仅当A为True且B为False时才返回False。否则暗示是真的。
![](http://sites.millersville.edu/bikenaga/math-proof/truth-tables/truth-tables13.png)
注意:含义通常用于直接数学证明。 A代表假设而B代表结论。
条件为假的唯一时间是真值导致假值。
| A | B | IFAB| | --- | --- | --- | | F | t | t | | F | f | t | | T | t | t | | T | f | f |
**逻辑等价iffif和only if**
“P当且仅当Q”与“P暗示Q和Q暗示P”相同。换句话说P和Q的真值表对于所有真值都是相同的。 这被称为双条件。它相当于A - > B **AND** B-> A.这意味着必须满足两个条件才能使双条件成立。
您可以很容易地看到真值表中IFF运算符的输出与第3列和第4列的AND运算相同。
| A | B | IFAB| IFBA| IFFAB| | --- | --- | --- | --- | --- | | F | t | t | f | f | | F | f | t | t | t | | T | t | t | t | t | | T | f | f | t | f |
#### 更多信息:
\+ \* [Javascript中的逻辑运算符](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators) + \* [PHP中的逻辑运算符](http://php.net/manual/en/language.operators.logical.php) + \* [C ++中的逻辑运算符](http://en.cppreference.com/w/cpp/language/operator_logical)