8.8 Case

  1. case Expr of
  2. Pattern1 [when GuardSeq1] ->
  3. Body1;
  4. ...;
  5. PatternN [when GuardSeqN] ->
  6. BodyN
  7. end

The expression Expr is evaluated and the patterns Pattern are sequentially matched against the result. If a match succeeds and the optional guard sequence GuardSeq is true, the corresponding Body is evaluated.

The return value of Body is the return value of the case expression.

If there is no matching pattern with a true guard sequence, a case_clause run-time error occurs.

Example:

  1. is_valid_signal(Signal) ->
  2. case Signal of
  3. {signal, _What, _From, _To} ->
  4. true;
  5. {signal, _What, _To} ->
  6. true;
  7. _Else ->
  8. false
  9. end.