Go logic operators are used to combine boolean values.
The following table lists the Go logic operators:
Operator | Name | Description | Example |
---|---|---|---|
&& | Logical And | Returns true if both statements are true | x < y && x > z |
|| | Logical Or | Returns true if one of the statements is true | x < y || x > z |
! | Logical Not | Reverse the result, returns false if the result is true | !(x == y && x > z) |
The following example shows how to use logical operators.
package main //from w w w. j a v a 2s . c o m import "fmt" func main() { var x, y, z = 10, 20, 30 fmt.Println(x < y && x > z) fmt.Println(x < y || x > z) fmt.Println(!(x == y && x > z)) }