CH07-L03 · applied

Prioritized decisions

Write ordered rules so that the first matching branch determines the result.

General CELRuns hereDocumented
What will I learn?

You can explain branch order, short-circuit evaluation, and the shared result type of the conditions.

Where will I try it?

Directly below, in the browser playground.

What do I do?

Run both modes, compare where their values come from, then complete the task.

Try CEL · browser pilot

Try both ways to supply values

Define local values inside one CEL expression, or provide variables as JSON input. Everything runs in your browser.

CEL pilot subset
One self-contained CEL expressioncel.bind() gives a local name to a value and returns the result of the final expression.

cel.bind()cel.bind() is an optional official extension. It is not part of the core CEL language and may not be enabled by every host application.

Tip: press Ctrl/⌘ + Enter to run.
Result

Press Run CEL to evaluate the active example.

Pilot scope: literals, explicit conversions, local cel.bind() variables, JSON variables, lists, maps, presence, collection macros, core string checks, time values, arithmetic, comparisons, logic, and the conditional operator.

What you will do

Turn ordered requirements into a nested conditional expression. You will trace branch order and verify that every path returns a meaningful result of the same type.

How it works

request.blocked
  ? 'blocked'
  : request.score >= 90.0
    ? 'priority'
    : request.score >= 70.0
      ? 'standard'
      : 'review'

CEL evaluates the conditions from top to bottom. When it finds a true condition, it evaluates only that result branch. Later branches cannot change the outcome.

Decision table

OrderConditionResult
1request.blocked'blocked'
2request.score >= 90.0'priority'
3request.score >= 70.0'standard'
4no preceding match'review'

With a score of 82.0 and blocked: false, the result is 'standard'.

Your task

  1. Run the prepared expression.
  2. Set blocked to true and the score to 95.
  3. Swap the 90.0 and 70.0 thresholds and explain the incorrect result.

Expected observation: Blocking always takes priority. If the lower threshold is checked first, the higher branch is never reached for a score of 95.

Common mistake

Nested conditions are not a set of independent rules. Their order is part of the expression's meaning.

Show the explanation

A value can satisfy several conditions at once. The first true condition determines the result, so more specific or more important rules belong earlier.

Knowledge check

Why does request.score >= 90.0 come before request.score >= 70.0?

Key takeaway

Treat a nested conditional expression as a prioritized decision tree, and document its order with a table or clear formatting.

Sources

  • CEL-DEV — official overview of CEL conditional expressions.
  • CEL-LANG — official definition of the conditional operator and short-circuit evaluation.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.