Conditional structures: Difference between revisions

Content added Content deleted
m (→‎{{header|Scala}}: Rm Scala imp category)
(jq)
Line 1,829: Line 1,829:


<lang javascript>var num = window.obj ? obj.getNumber() : null;</lang>
<lang javascript>var num = window.obj ? obj.getNumber() : null;</lang>

=={{header|jq}}==
jq's main conditional construct is:<lang jq>if cond then f else g end</lang>where cond, f, and g, are filters, and where cond may evaluate to anything at all, it being understood that:
# all JSON values are truthy except for false and null;
# if cond evaluates to nothing (i.e., produces an empty stream), then the entire if-then-else-end expression also produces an empty stream.

For example:<lang jq>
if empty then 2 else 3 end # produces no value
if 1 then 2 else 3 end # produces 2
if [false, false] then 2 else 3 end # produces 2
if (true, true) then 2 else 3 end # produces a stream: 2, 2
</lang>Notice that if cond produces a nonempty stream, then the entire expression will typically do the same. Since f and g also can produce streams, this lends itself to interesting Cartesian-product possibilities.

Since jq's <tt>and</tt> and <tt>or</tt> are short-circuiting, they can also be used for branching.


=={{header|LabVIEW}}==
=={{header|LabVIEW}}==
Line 1,837: Line 1,851:
Select is similar to the Ternary operator in text-based languages.<br/>
Select is similar to the Ternary operator in text-based languages.<br/>
[[File:LabVIEW_Select.png]]
[[File:LabVIEW_Select.png]]

=={{header|Lisaac}}==
=={{header|Lisaac}}==
{{works with|Lisaac|0.13.1}}
{{works with|Lisaac|0.13.1}}