Comparison Operators
We discussed three comparison operators in previous chapters. However, there are additional operators in this category that we should be familiar with. Below is a list of all the comparison operators:
Operator | Logic |
---|---|
== | Equal to |
!= | Not Equal to |
< | Less Than |
<= | Less Than or Equal to |
> | Greater Than |
>= | Greater Than or Equal to |
Not Equal To (!=)
This operator is used to check if two values are not equal to each other. For example:
index.go
12var a int = 1 fmt.Println(a != 2) // Outputs 'true'
Less Than or Equal To (<=)
This operator is used to check if the value on the left is less than or equal to the value on the right:
index.go
123var a int = 7 fmt.Println(a <= 7) // Outputs 'true' fmt.Println(a <= 6) // Outputs 'false'
Greater Than or Equal To (>=)
This operator is used to check if the value on the left is greater than or equal to the value on the right:
index.go
123var a int = 7 fmt.Println(a >= 7) // Outputs 'true' fmt.Println(a >= 6) // Outputs 'true'
Tak for dine kommentarer!
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 1.96
Comparison Operators
Stryg for at vise menuen
We discussed three comparison operators in previous chapters. However, there are additional operators in this category that we should be familiar with. Below is a list of all the comparison operators:
Operator | Logic |
---|---|
== | Equal to |
!= | Not Equal to |
< | Less Than |
<= | Less Than or Equal to |
> | Greater Than |
>= | Greater Than or Equal to |
Not Equal To (!=)
This operator is used to check if two values are not equal to each other. For example:
index.go
12var a int = 1 fmt.Println(a != 2) // Outputs 'true'
Less Than or Equal To (<=)
This operator is used to check if the value on the left is less than or equal to the value on the right:
index.go
123var a int = 7 fmt.Println(a <= 7) // Outputs 'true' fmt.Println(a <= 6) // Outputs 'false'
Greater Than or Equal To (>=)
This operator is used to check if the value on the left is greater than or equal to the value on the right:
index.go
123var a int = 7 fmt.Println(a >= 7) // Outputs 'true' fmt.Println(a >= 6) // Outputs 'true'
Tak for dine kommentarer!