Template:Switch

From ZeldaChaos
Jump to: navigation, search

This template is the functional equivalent of a switch-case statement in programming languages like JavaScript and C++, with the exception that it doesn't support fall-through. It was taken from Wikipedia.

If this wiki ever gets ParserFunctions, this template will be rendered obsolete, but until then, it's an effective way to get a switch-case statement. Here's an example of its use:

Code Result
{{switch
  |{{CURRENTDOW}}
  |case: 1=Mon
  |case: 2=Tue
  |case: 3=Wed
  |case: 4=Thu
  |case: 5=Fri
  |case: 6=Sat
  |case: 0=Sun
  |default=No date
}}
Sun

The code above takes the current day of the week (which is stored as an integer) and translates it into a human-readable string of text.

Personal tools
Namespaces

Variants
Actions
Glitches
Navigation
Affiliates
Toolbox
Google AdSense