Short-circuit evaluation: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 4,445: | Line 4,445: | ||
T F OR T a() |
T F OR T a() |
||
T T OR T a() |
T T OR T a() |
||
</pre> |
|||
=={{header|Wren}}== |
|||
Wren has the '''&&''' and '''||''' short-circuiting operators found in many C family languages. |
|||
<lang ecmascript>var a = Fn.new { |bool| |
|||
System.print(" a called") |
|||
return bool |
|||
} |
|||
var b = Fn.new { |bool| |
|||
System.print(" b called") |
|||
return bool |
|||
} |
|||
var bools = [ [true, true], [true, false], [false, true], [false, false] ] |
|||
for (bool in bools) { |
|||
System.print("a = %(bool[0]), b = %(bool[1]), op = && :") |
|||
a.call(bool[0]) && b.call(bool[1]) |
|||
System.print() |
|||
} |
|||
for (bool in bools) { |
|||
System.print("a = %(bool[0]), b = %(bool[1]), op = || :") |
|||
a.call(bool[0]) || b.call(bool[1]) |
|||
System.print() |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
a = true, b = true, op = && : |
|||
a called |
|||
b called |
|||
a = true, b = false, op = && : |
|||
a called |
|||
b called |
|||
a = false, b = true, op = && : |
|||
a called |
|||
a = false, b = false, op = && : |
|||
a called |
|||
a = true, b = true, op = || : |
|||
a called |
|||
a = true, b = false, op = || : |
|||
a called |
|||
a = false, b = true, op = || : |
|||
a called |
|||
b called |
|||
a = false, b = false, op = || : |
|||
a called |
|||
b called |
|||
</pre> |
</pre> |
||