From the course: Learning Go
Unlock this course with a free trial
Join today to access over 24,200 courses taught by industry experts.
Evaluate expressions with switch statements - Go Tutorial
From the course: Learning Go
Evaluate expressions with switch statements
- [Instructor] Go switch statement serves the same purpose as an other C-style languages, but its syntax expands on those languages. For this demonstration, I'm starting with a randomized value. I'm using a package called math slash Rand and another package the time package that we've seen before. From the rand package, I'm calling the seed function and passing in the current time in Unix format. Then I'm using a function called Intn and passing in a ceiling of seven, and then adding one, and this will give me a number between one and seven. Each time I run the application, I'll get possibly a different number. And it all depends on the millisecond of the current time on my computer. It is possible to see the same number over and over again. But that's just coincidence. If I ran the same code in the go playground online, I would always get the same number, because in that environment, it's always the same date and…