ADVERTISEMENT
ADVERTISEMENT

Golang Relational Operators

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

Relational Operators

Relational operators are used for making decisions, they are used to compare the expressions such as greater than, less than, equal to, etc. Relational operators return the Boolean value i.e., true or false.

List of Golang Relational Operators

Operator Description Example
x:=5
y:=2
Equal To (==) Returns true if the values of both operands are equal; false, otherwise. x==y returns false
Not Equal To (!=) Returns true if the values of both operands are not equal; true, otherwise. x!=y returns true
Greater Than (>) Returns true if the value of the first operand is greater than the second operator; false, otherwise. x>y returns true
Less Than (<) Returns true if the value of the first operand is less than the second operator; false, otherwise. x<y returns false
Greater Than or Equal To (>=) Returns true if the value of the first operand is greater than or equal to the second operator; false, otherwise. x>=y returns true
Less Than or Equal To (<=) Returns true if the value of the first operand is less than or equal to the second operator; false, otherwise. x<=y returns false

Example of Golang Relational Operators

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

// Golang program demonstrate the
// example of relational operators

package main

import "fmt"

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

	result = x == y
	fmt.Println(x, "==", y, "=", result)

	result = x != y
	fmt.Println(x, "!=", y, "=", result)

	result = x < y
	fmt.Println(x, "<", y, "=", result)

	result = x > y
	fmt.Println(x, ">", y, "=", result)

	result = x >= y
	fmt.Println(x, ">=", y, "=", result)

	result = x <= y
	fmt.Println(x, "<=", y, "=", result)
}

Output:

5 == 2 = false
5 != 2 = true
5 < 2 = false
5 > 2 = true
5 >= 2 = true
5 <= 2 = false

ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.