Case expression

The case expression is again very similar to the case statement:

  1. var favoriteFood = case animal
  2. of "dog": "bones"
  3. of "cat": "mice"
  4. elif animal.endsWith"whale": "plankton"
  5. else:
  6. echo "I'm not sure what to serve, but everybody loves ice cream"
  7. "ice cream"

As seen in the above example, the case expression can also introduce side effects. When multiple statements are given for a branch, Nim will use the last expression as the result value.