Go switch: Difference between revisions
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
Same as for <code>if</code>, <code>switch</code> accepts an [[Go_if#Overview|optional initialization statement]]. | Same as for <code>if</code>, <code>switch</code> accepts an [[Go_if#Overview|optional initialization statement]]. | ||
The cases are evaluated top to bottom until a match is found. The expressions need not be constants or even integers. | |||
It is idiomatic to write an <code>if</code>-<code>else</code>-<code>if</code>-<code>else</code> as a <code>switch</code>. | |||
=Tagless Switch= | =Tagless Switch= |
Latest revision as of 00:07, 13 August 2024
Internal
Overview
Same as for if
, switch
accepts an optional initialization statement.
The cases are evaluated top to bottom until a match is found. The expressions need not be constants or even integers.
It is idiomatic to write an if
-else
-if
-else
as a switch
.