Posts

Showing posts with the label switch

Condition Construct in GOLang

Image
Condition Construct in GOLang Conditional programming is a very important construct available in all the programming languages. Go provides 2 conditional programming constructs If else Switch If Else This is a very basic construct and is similar to most of the other languages. If else can be written in the following way: package main import "fmt" func main() { i := 10 if i > 10 { fmt.Println("Greater than 10") } else { fmt.Println("Less than 10") } } We can also create an IF Else ladder in Golang package main import "fmt" func main() { i := 7 if i > 10 { fmt.Println("Greater than 10") } else if i > 5 { fmt.Println("Greater than 5") } else { fmt.Println("Less than 5") } } Switch Statement Another alternative to IF Else is a Switch statement which is quite useful in Golang. Following is a very basic example of a switch statement pa