News for hackers. Stuff that matters.
Re:If-else vs switch – Which is better? by apu on Monday August 03, 2009 @02:25AM (#738724)
This is similar to the accepted idiom in python as well: create a dictionary mapping choices to outcomes.

For the special case of sequential numerical choices, a list works as well.

For the special-special case of numerical choices for single-word string outcomes, I often use:

  dir = 'north eash south west'.split()[n]

There are no comments on this comment yet.