Short-circuit evaluation: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,976: | Line 1,976: | ||
x = a(i) and b(i); print "" |
x = a(i) and b(i); print "" |
||
y = a(i) or b(i)</lang> |
y = a(i) or b(i)</lang> |
||
=={{header|Maple}}== |
|||
Built-in short circuit evaluation |
|||
<lang Maple>a := proc(bool) |
|||
printf("a is called->%s\n", bool): |
|||
return bool: |
|||
end proc: |
|||
b := proc(bool) |
|||
printf("b is called->%s\n", bool): |
|||
return bool: |
|||
end proc: |
|||
for i in [true, false] do |
|||
for j in [true, false] do |
|||
printf("calculating x := a(i) and b(j)\n"): |
|||
x := a(i) and b(j): |
|||
printf("calculating x := a(i) or b(j)\n"): |
|||
y := a(i) or b(j): |
|||
od: |
|||
od:</lang> |
|||
{{Out|Output}} |
|||
<pre>calculating x := a(i) and b(j) |
|||
a is called->true |
|||
b is called->true |
|||
calculating x := a(i) or b(j) |
|||
a is called->true |
|||
calculating x := a(i) and b(j) |
|||
a is called->true |
|||
b is called->false |
|||
calculating x := a(i) or b(j) |
|||
a is called->true |
|||
calculating x := a(i) and b(j) |
|||
a is called->false |
|||
calculating x := a(i) or b(j) |
|||
a is called->false |
|||
b is called->true |
|||
calculating x := a(i) and b(j) |
|||
a is called->false |
|||
calculating x := a(i) or b(j) |
|||
a is called->false |
|||
b is called->false</pre> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |