Case() efficiency and short-circuit evaluation

Expert

Understand how FileMaker evaluates Case() branches and write conditions in the right order for clarity and performance.

What you'll learn

  • How Case() stops evaluating after the first true condition
  • Why ordering conditions from most to least specific avoids bugs
  • How to use the default (last) argument as an else clause

FileMaker's Case() function evaluates conditions left to right and returns the result of the first true condition without evaluating further branches. This short-circuit behavior means condition order matters — both for correctness and performance. Expensive sub-expressions should be placed in later branches, guarded by cheap early conditions.

1/3
1

Short-circuit evaluation

Case(c1; r1; c2; r2; ...; default) returns r1 if c1 is true, without evaluating c2, r2, or default. Place the most common or cheapest conditions first to minimize evaluation.

FileMaker Script
Case (
  IsEmpty ( $value )         ; "empty"    ;  // cheap check first
  Length ( $value ) > 1000   ; "too long" ;  // more expensive
  PatternCount ( $value ; "<script>" ) > 0 ; "unsafe" ;  // most expensive last
  $value  // default
)

Sign in to track your progress and pick up where you left off.

Sign in to FM Dojo