Help:Switch parser function

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.

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.

  1. ^ A template call (also known as template tag) has two "braces" on either side of the template page name and does not require the "Template:" prefix. For example, the following are equivalent template calls: {{Template:Foobar}} and {{Foobar}}.

Developed by StudentB