Go switch: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Go Language =Overview= ===Tagless Switch===")
 
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
=Overview=
=Overview=


===Tagless Switch===
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=

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.

Tagless Switch