Go Logical Operators

Gayathri. B

 Logical Operators

  • Logical operators are used to evaluate the relationship between two or more conditions or expressions. They return a Boolean value (true or false) based on the logic applied.
Operator                   Name                                 Description
  1. &&                   Logical AND           Returns true if both conditions are true
     `2.   !                    Logical NOT         Reverses the result, returns false if condition is true

Example:

package main
import "fmt"
func main() {
  x := 5
  y := 10
  fmt.Println(x > 3 && y < 15)  // true  (both are true)
  fmt.Println(x > 6 || y < 15)  // true  (one condition is true)
  fmt.Println(!(x > 6))         // true  (x > 6 is false, NOT false is true)
}
Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send