Short-circuit evaluation: Difference between revisions

m
m (Updated description and link for Fōrmulæ solution)
Line 2,187:
b is called->false</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Mathematica has built-in short-circuit evaluation of logical expressions.
<lang Mathematica>a[in_] := (Print["a"]; in)
b[in_] := (Print["b"]; in)
 
a[False] && b[True]
a[True] || b[False]</lang>
Evaluation of the preceding code gives:
<pre>a
a
False
 
a
True</pre>
</pre>
Whereas evaluating this:
<lang Mathematica>a[True] && b[False]</lang>
Gives:
<pre>a
a
b
False</pre>
</pre>
 
=={{header|MATLAB}} / {{header|Octave}}==
1,111

edits