「Go言語」演算子(==, <= , >= )を利用するサンプル

書式
var 変数名 int = xxx
使用例

package main

import "fmt"

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

   if( a == b ) {
      fmt.Printf("line 1 - a = b\n" )
   } else {
      fmt.Printf("line 1 - a not = b\n" )
   }
   if ( a < b ) {
      fmt.Printf("line 2 - a <  b\n" )
   } else {
      fmt.Printf("line 2 - a not <  b\n" )
   }
   
   if ( a > b ) {
      fmt.Printf("line 3 - a > b\n" )
   } else {
      fmt.Printf("line 3 - a not > b\n" )
   }
   /* Lets change value of a and b */
   a = 5
   b = 20
   if ( a <= b ) {
      fmt.Printf("line 4 - a < = b\n" )
   }
   if ( b >= a ) {
      fmt.Printf("line 4 - b >= a\n" )
   }
}

実行結果
C:\golesson>go run test.go
line 1 – a not = b
line 2 – a not < b
line 3 – a > b
line 4 – a < = b
line 4 – b >= a

Go言語

Posted by arkgame