Conditional expressions

Figure 39. IfExpr

IfExpr

A conditional expressions allows you to pick one or another value depending on a boolean value.

Example 89. A conditional expression

if (1 + 1 eq 2) then { "foo" : "yes" } else { "foo" : "false" }
      

Result (run with Zorba): { "foo" : "yes" }


The behavior of the expression inside the if is similar to that of logical operations (two-valued logics), meaning that non-boolean values get converted to a boolean.

Example 90. A conditional expression

if (null) then { "foo" : "yes" } else { "foo" : "no" }
      

Result (run with Zorba): { "foo" : "no" }


Example 91. A conditional expression

if (1) then { "foo" : "yes" } else { "foo" : "no" }
      

Result (run with Zorba): { "foo" : "yes" }


Example 92. A conditional expression

if (0) then { "foo" : "yes" } else { "foo" : "no" }
        

Result (run with Zorba): { "foo" : "no" }


Example 93. A conditional expression

if ("foo") then { "foo" : "yes" } else { "foo" : "no" }
      

Result (run with Zorba): { "foo" : "yes" }


Example 94. A conditional expression

if ("") then { "foo" : "yes" } else { "foo" : "no" }
        

Result (run with Zorba): { "foo" : "no" }


Example 95. A conditional expression

if (()) then { "foo" : "yes" } else { "foo" : "no" }
        

Result (run with Zorba): { "foo" : "no" }


Example 96. A conditional expression

if (({ "foo" : "bar" }, [ 1, 2, 3, 4])) then { "foo" : "yes" } else { "foo" : "no" }
        

Result (run with Zorba): { "foo" : "yes" }


Note that the else clause is mandatory (but can be the empty sequence)

Example 97. A conditional expression

if (1+1 eq 2) then { "foo" : "yes" } else ()
        

Result (run with Zorba): { "foo" : "yes" }