previous |
start |
next
De Morgan's Law
- Negating a complex condition can be confusing:
if (!(0 < amount && amount < 1000))
- De Morgan's law states that
!(A && B) is the same as !A || !B
!(A || B) is the same as !A &&
!B
- Note that the && and || flip when
moving the ! inwards
- (!(0 < amount && amount < 1000)) is
!(0 < amount) || !(amount < 1000) , that is
0 >= amount || amount >= 1000
- Note that the opposite of < is >=
previous |
start |
next