CH01-L03 · foundation

Operators and logic

Combine a comparison, list membership, and a logical condition.

General CELRuns hereDocumented
What will I learn?

You can split a compound condition into smaller parts and verify each one.

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

You will run the prepared expression in the playground above, change one input at a time, and explain the result. Start in CEL only, then repeat the same rule in CEL + JSON.

How it works

The expression contains two independent questions. The in operator checks whether role equals an item in the list. The && operator then requires that result and active both be true. CEL short-circuits &&: if the left side is false, the complete result is already known.

Read the prepared example

The CEL + JSON rule is:

role in ['editor', 'admin'] && active

Its input is:

{
  "role": "editor",
  "active": true
}

The CEL only tab contains the values and the rule in one expression. The enabled cel.bind() extension keeps each name local to its final argument.

Evaluation step by step

  1. 'editor' in ['editor', 'admin'] returns true.
  2. active is true.
  3. Both sides of && are true, so the result is true.

Your task

  1. Run the initial expression.
  2. Change role to viewer and explain the new result.
  3. Restore editor, change active to false, and run again.

Expected observation: Either change makes the whole expression return false.

Common mistake

Reading the condition as one long sentence hides which part failed. Evaluate each side of && separately when debugging.

Show the explanation

The role must occur in the allowed list and active must also be true.

Knowledge check

What must be true for the full expression to return true?

Key takeaway

Split compound logic at && and ||; each side must have a clear boolean meaning.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition.
  • CEL-GO-BIND — official documentation for the optional cel.bind() extension used by the self-contained tab.