Saturday, 22 August 2015

Basic Go: Switch

You probably knew what switch was going to look like.

A case body breaks automatically, unless it ends with a fallthrough statement.


Switch evaluation order

Switch cases evaluate cases from top to bottom, stopping when a case succeeds.
(For example,
switch i {
case 0:
case f():
}
does not call f if i==0.)
Note: Time in the Go playground always appears to start at 2009-11-10 23:00:00 UTC, a value whose significance is left as an exercise for the reader.


Switch with no condition

Switch without a condition is the same as switch true.
This construct can be a clean way to write long if-then-else chains.

Do comment, if it worked/Not worked for you.

No comments:

Post a Comment