Files
learngo/14-arrays/02-examples-1-hipsters-love-bookstore/main.go
2018-11-13 17:43:25 +03:00

34 lines
688 B
Go

package main
// STORY:
// Hipster's Love store publishes limited books
// twice a year.
//
// The number of books they publish is fixed at 4.
// So, let's create a 4 elements string array for the books.
const (
winter = 1
summer = 3
yearly = winter + summer
)
func main() {
// var books [4]string
// var books [1 + 3]string
var books [yearly]string
books[0] = "Kafka's Revenge"
books[1] = "Stay Golden"
books[2] = "Everythingship"
books[3] += books[0] + " 2nd Edition"
// Go compiler can catch indexing errors when constant is used
// books[4] = "Neverland"
// Go compiler cannot catch indexing errors when non-constant is used
// i := 4
// books[i] = "Neverland"
}