Like the highly popular Hello World code that we use to learn as our first program in any programming language; Fizz-Buzz is one step ahead which helps us to understand the basic nitty-gritty of a language. Also, it's a popular interview question that can be asked even to experienced programmers to check if s/he can actually write code!
And you know what, most of them fail to write this even if they are working in the said language for say 4+ years! Has Ctrl+C, Ctrl+V taken a toll on our code writing ability :)
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “Fizz-Buzz”.
Expected Output Sample [Shown only till 20 and not 100]
FizzBuzz using If / Else
FizzBuzz using Switch
Run this code at Playground and see the Output.
Hope this helps you to get started with the basic control flow of Google Go language. Please share your views.