FEEL conditionals and loops
FEEL language guide · 4 constructs · DMN 1.6
FEEL has no statements. if … then … else picks one of two values, for … in … return builds a new list from an old one, and some and every test the elements of a list. Each of them is an expression that returns a value, so you can nest them and use them anywhere a value fits.
The part that catches people is null. A condition that evaluates to null takes the else branch, and a quantifier can return null instead of false. Each case is shown below with the result the engine computed.
| Construct | Syntax |
|---|---|
| if … then … else | if condition then expression else expression |
| for … in … return | for name in list return expression |
| some … satisfies | some name in list satisfies condition |
| every … satisfies | every name in list satisfies condition |
if … then … else
if picks one of two values depending on a condition. Unlike an if statement in a programming language it is an expression: it always yields a value, so the else branch is mandatory. The condition must evaluate to a boolean; anything else (including null, a common cause of surprising decisions) takes the else branch.
if condition then expression else expression
| Element | Type | Description |
|---|---|---|
| condition | boolean | the test; a non-boolean result selects the else branch |
| then | any | value if the condition is true |
| else | any | value otherwise; not optional |
if 5 > 3 then "yes" else "no"
if null then "a" else "b"
if 1 > 2 then "a" else if 2 > 1 then "b" else "c"
if {age: 34}.age >= 18 then "adult" else "minor"
Related: null and error propagation · comparison and boolean operators · not
for … in … return
for is FEEL's iteration construct, the equivalent of a map or a for loop in other languages. It evaluates the return expression once per element and collects the results into a new list; it never mutates anything. Several iteration contexts separated by commas produce the cartesian product, and a range can be iterated directly instead of a list.
for name in list return expression
| Element | Type | Description |
|---|---|---|
| name | name | the iteration variable, visible inside the return expression |
| list | list or range | what to iterate; a..b iterates the integers of a range |
| return | any | evaluated per element; results are collected into a list |
for i in [1,2,3] return i * 2
for i in 1..4 return i * i
for x in [1,2], y in [10,20] return x + y
for c in ["a","b"] return upper case(c)
Related: list filter […] · some … satisfies · every … satisfies · count · sum
some … satisfies
some tests whether at least one element of a list satisfies a condition. The result is true as soon as the condition gives true for one element. When no element gives true and at least one gives null or a non-boolean, the result is null rather than false: some x in [1, null] satisfies x > 1 is null. B-FEEL always answers true or false and gives false there. An empty list gives false. This is the usual way to write an "any of" condition in a literal expression.
some name in list satisfies condition
| Element | Type | Description |
|---|---|---|
| name | name | the iteration variable |
| list | list or range | the elements to test |
| satisfies | boolean | the condition evaluated per element |
some x in [1,5,9] satisfies x > 8
some x in [1,2] satisfies some y in [3,4] satisfies x + y = 5
some order in [{total: 50}, {total: 150}] satisfies order.total > 100
some x in [1, null] satisfies x > 1
Related: every … satisfies · for … in … return · list filter […] · any · count
every … satisfies
every tests whether all elements of a list satisfy a condition. The result is false as soon as the condition gives false for one element, and true when it gives true for every element. When no element gives false and at least one gives null or a non-boolean, the result is null: every x in [1, null] satisfies x > 0 is null in FEEL and false in B-FEEL. An empty list satisfies it vacuously, which is the usual source of surprise when a validation rule passes for a record with no line items.
every name in list satisfies condition
| Element | Type | Description |
|---|---|---|
| name | name | the iteration variable |
| list | list or range | the elements to test |
| satisfies | boolean | the condition evaluated per element |
every x in [1,5,9] satisfies x > 0
every x in [] satisfies x > 100
every item in [{qty: 1}, {qty: 2}] satisfies item.qty > 0
every x in [1, null] satisfies x > 0
Related: some … satisfies · for … in … return · all · count
Related guides
Every result on this page was computed by the Impulse FEEL engine 0.9.1, the interpreter that runs the playground. Last updated .
Defined by the OMG DMN 1.6 specification, chapter 10.3 (the FEEL grammar and semantics).