Conditional structures: Difference between revisions

Content deleted Content added
No edit summary
Add Maple example
Line 1,973:
|gmake -f if.mk A=0
0 .. false</lang>
 
=={{header|Maple}}==
Maple offers both conditional statements and conditional functions.
 
=== Conditional statements ===
Example syntax for conditional statements:
<code>if x > 0 then
res := x;
else
res := -x;
end if;</code>
 
Example syntax for conditional statements with else-if:
<code>if x = 0 then
res := y;
elif y = 0 then
res := x;
else
res := sqrt(x^2+y^2);
end if;</code>
 
=== Conditional functions ===
The function <code>`if`(cond,a,b)</code> (note the backtick <code>`</code> delimiters) returns ''a'' when ''cond'' is true and ''b'' otherwise.
 
<code>res := `if`(n::even, n/2, 3*n+1);</code>
 
The piecewise command can be used for functional evaluation in which there is more than one branch. The following is equivalent to the if/then construct from the previous section.
 
<code>res := piecewise(x=0, y, y=0, x, sqrt(x^2+y^2));</code>
 
=={{header|Mathematica}}==