Friday 3 May 2019

Go language: switch without an expression


Syntax
switch {

         case caseStatement1 :
                  statements

         case caseStatement2 :
                  statements

         …..
…..
default :
         statements
         break
}

HelloWorld.go
package main

import "fmt"

func main() {

 a := 10

 switch {
 case a > 10:
  fmt.Println("Value of a is  > 10")

 case a <= 10:
  fmt.Println("Value of a is <= 10")
 }
}

Output
Value of a is <= 10



Previous                                                 Next                                                 Home

No comments:

Post a Comment