Logical Operators in Go #
Logical operators are used to determine the logic between variables or values.
List of Logical Operators #
Operator | Name | Description | Example |
---|---|---|---|
&& | Logical AND | Returns true if both statements are true | x < 5 && x < 10 |
` | ` | Logical OR | |
! | Logical NOT | Reverses the result, returns false if true | !(x < 5 && x < 10) |
Example #
package main
import ("fmt")
func main() {
var x = 3
fmt.Println(x < 5 && x < 10) // true, both conditions are true
fmt.Println(x < 5 || x < 4) // true, at least one condition is true
fmt.Println(!(x < 5 && x < 10)) // false, reverses the result
}