![]() | This help page is a how-to guide. It explains concepts or processes used by the Wikipedia community. It is not one of Wikipedia's policies or guidelines, and may reflect varying levels of consensus. |
The switch parser function, coded as "#switch", selects the first matching branch in a list of choices, acting as a case statement.
Each branch can be a value, an expression (calculation), or a template call,[1] evaluated and compared to match the value of the switch. Although many #switch structures are used to branch among a simple set of values, the branches can also include boolean expressions to act as a set of pre-conditions to be tested until one tests true, acting as an if-elseif-elseif-elseif-else structure. The switch value is compared as a character string, not a number, so "5" would not match "5.00" unless compared as "{{#expr:{{{1|5.00}}} }}" (="5")
.
A #switch can contain over 1,000 branches, but for better speed should be split to have less than 100 branches, in each of multiple or nested parts. The upper branches execute faster, and the bottom branches must wait for comparisons of all higher branches. Because it is a parser function, a #switch can be used inside any page, even in article text, but in most cases, a #switch is typically used inside a template, to branch depending on a parameter value passed to the template.
{{Template:Foobar}}
and {{Foobar}}
.
© MMXXIII Rich X Search. We shall prevail. All rights reserved. Rich X Search