Go-Cheatsheet

๐Ÿ‘‹ Hello World package main import "fmt" func main() { fmt.Println("Hello, World!") } ๐Ÿ’ก Tip: Every Go program starts with package main and a main() function. ๐Ÿ“ฆ Variables & Constants package main import "fmt" func main() { var name string = "Maxon" age := 25 // short declaration const pi = 3.14159 fmt.Println(name, age, pi) } ๐Ÿ’ก Tip: Use := for short variable declarations. Constants use const . ๐Ÿ”ข Data Types var a int = 42 var b float64 = 3.14 var c string = "Gopher" var d bool = true ๐Ÿ’ก Tip: Go is statically typed but infers types automatically when possible. ๐Ÿ”€ Control Flow for i := 1; i <= 5; i++ { if i%2 == 0 { fmt.Println(i, "is Even") } else { fmt.Println(i, "is Odd") } } switch day := 3; day { case 1: fmt.Println("Mon") case 2: fmt.Println("Tue") default: fmt.Println("Other") } ๐Ÿ’ก Tip: Go has no while — only for loops wi…

Post a Comment