Friday, 3 May 2019

Go language: if-else statement


Syntax
if condition {

} else {

}

If the condition evaluates to true, then the block of statements followed by if block are executed, else the statements followed by else block are executed.

HelloWorld.go
package main

import "fmt"

func main() {

 a := 10

 if a == 10 {
  fmt.Println("Value of a is 10")
 }else {
  fmt.Println("Value of a is 11")
 }
}

Output
Value of a is 10



Previous                                                 Next                                                 Home

No comments:

Post a Comment