Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [SIZE=7][B]Logical Operator: &&[/B][/SIZE]
- The [ICODE]and[/ICODE] logical operator is denoted by [ICODE]&&[/ICODE].
- It returns [ICODE]true[/ICODE] if the condition on the left [I]and[/I] the condition on the right are both [ICODE]true[/ICODE]. Otherwise, it returns [ICODE]false[/ICODE].
- Here’s the truth table:
- [TABLE]
- [TR]
- [TH]a[/TH]
- [TH]b[/TH]
- [TH]a && b[/TH]
- [/TR]
- [TR]
- [TD]false[/TD]
- [TD]false[/TD]
- [TD]false[/TD]
- [/TR]
- [TR]
- [TD]false[/TD]
- [TD]true[/TD]
- [TD]false[/TD]
- [/TR]
- [TR]
- [TD]true[/TD]
- [TD]false[/TD]
- [TD]false[/TD]
- [/TR]
- [TR]
- [TD]true[/TD]
- [TD]true[/TD]
- [TD]true[/TD]
- [/TR]
- [/TABLE]
- For instance:
- [LIST]
- [*][ICODE]( 1 < 2 && 2 < 3 )[/ICODE] returns [ICODE]true[/ICODE]
- [*][ICODE]( 1 < 2 && 2 > 3 )[/ICODE] returns [ICODE]false[/ICODE]
- [/LIST]
- [B]Note:[/B] The keyword [ICODE]and[/ICODE] can also be used in the place of [ICODE]&&[/ICODE].
- [SIZE=7][B]Logical Operator: II[/B][/SIZE]
- The [ICODE]or[/ICODE] logical operator is denoted by [ICODE]||[/ICODE].
- It returns [ICODE]true[/ICODE] when the condition on the left is [ICODE]true[/ICODE] [I]or[/I] the condition on the right is [ICODE]true[/ICODE]. Only one of them needs to be [ICODE]true[/ICODE].
- Here’s the truth table:
- [TABLE]
- [TR]
- [TH]a[/TH]
- [TH]b[/TH]
- [TH]a || b[/TH]
- [/TR]
- [TR]
- [TD]false[/TD]
- [TD]false[/TD]
- [TD]false[/TD]
- [/TR]
- [TR]
- [TD]false[/TD]
- [TD]true[/TD]
- [TD]true[/TD]
- [/TR]
- [TR]
- [TD]true[/TD]
- [TD]false[/TD]
- [TD]true[/TD]
- [/TR]
- [TR]
- [TD]true[/TD]
- [TD]true[/TD]
- [TD]true[/TD]
- [/TR]
- [/TABLE]
- For instance:
- [LIST]
- [*][ICODE]( 1 < 2 || 2 > 3 )[/ICODE] returns [ICODE]true[/ICODE]
- [*][ICODE]( 1 > 2 || 2 > 3 )[/ICODE] returns [ICODE]false[/ICODE]
- [/LIST]
- [B]Note:[/B] The keyword [ICODE]or[/ICODE] can be used in the place of [ICODE]||[/ICODE].
- [SIZE=7][B]Logical Operator: ![/B][/SIZE]
- The [ICODE]not[/ICODE] logical operator is denoted by [ICODE]![/ICODE].
- It reverses the [ICODE]bool[/ICODE] outcome of the expression that immediately follows.
- Here’s the truth table:
- [TABLE]
- [TR]
- [TH]a[/TH]
- [TH]!a[/TH]
- [/TR]
- [TR]
- [TD]false[/TD]
- [TD]true[/TD]
- [/TR]
- [TR]
- [TD]true[/TD]
- [TD]false[/TD]
- [/TR]
- [/TABLE]
- For instance:
- [LIST]
- [*][ICODE]( !true )[/ICODE] returns [ICODE]false[/ICODE]
- [*][ICODE]( !false )[/ICODE] returns [ICODE]true[/ICODE]
- [*][ICODE]( !(10 < 11) )[/ICODE] returns [ICODE]false[/ICODE]
- [/LIST]
- [B]Note:[/B] The keyword [ICODE]not[/ICODE] can be used in the place of [ICODE]![/ICODE].
- [SIZE=7][B]Review[/B][/SIZE]
- Awesome! In this mini-lesson, we’ve added more operators to our toolbox:
- [LIST]
- [*][ICODE]&&[/ICODE]: the [ICODE]and[/ICODE] logical operator
- [*][ICODE]||[/ICODE]: the [ICODE]or[/ICODE] logical operator
- [*][ICODE]![/ICODE]: the [ICODE]not[/ICODE] logical operator
- [/LIST]
Add Comment
Please, Sign In to add comment