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.

ConstructSyntax
if … then … elseif condition then expression else expression
for … in … returnfor name in list return expression
some … satisfiessome name in list satisfies condition
every … satisfiesevery 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

ElementTypeDescription
conditionbooleanthe test; a non-boolean result selects the else branch
thenanyvalue if the condition is true
elseanyvalue otherwise; not optional
if 5 > 3 then "yes" else "no"
returns yes Try it ↑
if null then "a" else "b"
returns b Try it ↑
if 1 > 2 then "a" else if 2 > 1 then "b" else "c"
returns b Try it ↑
if {age: 34}.age >= 18 then "adult" else "minor"
returns adult Try it ↑

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

ElementTypeDescription
namenamethe iteration variable, visible inside the return expression
listlist or rangewhat to iterate; a..b iterates the integers of a range
returnanyevaluated per element; results are collected into a list
for i in [1,2,3] return i * 2
returns [2, 4, 6] Try it ↑
for i in 1..4 return i * i
returns [1, 4, 9, 16] Try it ↑
for x in [1,2], y in [10,20] return x + y
returns [11, 21, 12, 22] Try it ↑
for c in ["a","b"] return upper case(c)
returns [A, B] Try it ↑

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

ElementTypeDescription
namenamethe iteration variable
listlist or rangethe elements to test
satisfiesbooleanthe condition evaluated per element
some x in [1,5,9] satisfies x > 8
returns true Try it ↑
some x in [1,2] satisfies some y in [3,4] satisfies x + y = 5
returns true Try it ↑
some order in [{total: 50}, {total: 150}] satisfies order.total > 100
returns true Try it ↑
some x in [1, null] satisfies x > 1
returns null Try it ↑

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

ElementTypeDescription
namenamethe iteration variable
listlist or rangethe elements to test
satisfiesbooleanthe condition evaluated per element
every x in [1,5,9] satisfies x > 0
returns true Try it ↑
every x in [] satisfies x > 100
returns true Try it ↑
every item in [{qty: 1}, {qty: 2}] satisfies item.qty > 0
returns true Try it ↑
every x in [1, null] satisfies x > 0
returns null Try it ↑

Related: some … satisfies · for … in … return · all · count

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).