WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Go - Relational Operators


The following table lists the relational operators for all Go languages. Suppose the A value is 10 and the B value is 20.

OperatorDescriptionInstance
== Checks if the two values are equal, and returns True if equal, otherwise returns False. (A == B) for False
!= Checks if the two values are not equal, and returns True if they are not equal, otherwise returns False. (A != B) for True
>Check if the left value is greater than the right value, and if it returns True, return False. (A > B) for False
<Check if the left value is less than the right value, and if it returns True, return False. (A < B) for True
>=Check if the left value is greater than or equal to the right value, and if it returns True, return False. (A >= B) for False
<= Check if the left value is less than or equal to the right value, and if it returns True, return False. (A <= B) for True

The following example demonstrates the use of relational operators:

example

package main

import "fmt"

func main() {
   var a int = 21
   var b int = 10

   if( a == b ) {
      fmt.Printf("first row - a equal b\n" )
   } else {
      fmt.Printf("first row - a Not equal b\n" )
   }
   if ( a < b ) {
      fmt.Printf("second line - a Less than b\n" )
   } else {
      fmt.Printf("second line - a Not Less than b\n" )
   }
   
   if ( a > b ) {
      fmt.Printf("The third row - a more than the b\n" )
   } else {
      fmt.Printf("The third row - a Not more than the b\n" )
   }
   /* Lets change value of a and b */
   a = 5
   b = 20
   if ( a <= b ) {
      fmt.Printf("Fourth line - a Less thanequal b\n" )
   }
   if ( b >= a ) {
      fmt.Printf("The fifth line - b more than theequal a\n" )
   }
}