×

# Golang Logical Operators

Here, we are going to learn about the Logical Operators in the Go programming language with examples.
Submitted by IncludeHelp, on December 07, 2021

## Logical Operators

Logical operators are used for making decisions based on multiple conditions, they are used to check multiple conditions, i.e., the logical operators are the symbols used to connect two or more expressions/conditions such that the value of the compound expression produced depends only on that of the original expressions and on the meaning of the operator. The common logical operators are Logical AND (&&), Logical OR (||), and Logical NOT (!).

## List of Golang Logical Operators

Operator Description Example
x:=5
y:=2
Logical AND (&&) It returns true if all operands are true; false, otherwise. x==5 && y==2 returns true
Logical OR (||) It returns true if any of the operands is true; false, otherwise. x==5 || y==2 returns true
Logical NOT (!) It returns true if the operand is false; false, otherwise. !(x==5) returns false

## Example of Golang Logical Operators

The below Golang program is demonstrating the example of logical operators.

```// Golang program demonstrate the
// example of logical operators

package main

import "fmt"

func main() {
x := 5
y := 2
var result bool

result = (x == 5 && y == 2)
fmt.Println("result:", result)

result = (x == 5 || y == 2)
fmt.Println("result:", result)

result = !(x == 5)
fmt.Println("result:", result)
}
```

Output:

```result: true
result: true
result: false
```