Logical Operators

Logical Operators in Go #

Logical operators are used to determine the logic between variables or values.

List of Logical Operators #

OperatorNameDescriptionExample
&&Logical ANDReturns true if both statements are truex < 5 && x < 10
``Logical OR
!Logical NOTReverses 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
}