A boolean value represents true and false.
Three logical operators are used with boolean values:
Here is an example program showing how they can be used:
package main/*from w w w . j a v a 2 s . c om*/ import "fmt" func main() { fmt.Println(true && true) fmt.Println(true && false) fmt.Println(true || true) fmt.Println(true || false) fmt.Println(!true) }
We usually use truth tables to define how these operators work:
Expression | Value |
---|---|
true && true | true |
true && false | false |
false && true | false |
false && false | false |
true || true | true |
true || false | true |
false || true | true |
false || false | false |
!true | false |
!false | true |