# Maple Flow Control

We know what tools we need from the Matlab page. The difference between Matlab and Maple flow control is generally that Maple is a bit more verbose than Matlab.

## If

The basic syntax is

ifAs always, theconditionalthenstatement sequence; elifconditionalthenstatement sequence; elsestatement sequence; end if;

`elif`and

`else`are optional.

The conditionals have a similar form to those in other languages.
There are a few differences. First, conditionals in Maple do
not have a truth value outside of the "if" statement context.
In other words, the expression "5>2" has no truth value in Maple,
but `if 5>2 then c:=3; end if;` has meaning. If you want to find
the truth value of a conditional outside of an "if" statement,
you must use the `evalb` function. Here is an example.

5=3+2;
5 = 5
evalb(5=3+2);
*true*
if 5>2 then
x:=3;
elif 5=2 then
x:=103;
end if;
*x *:= 3

It is worth a special note that Maple uses := for the assignment operator, which frees up = to be used to test equality. This differs from many other languages, which typically use == for that purpose. A table summarizing logical operators follows.

Symbol | Meaning |
---|---|

= | Is Equal To |

<> | Is Not Equal To |

> | Is Greater Than |

>= | Is Greater Than Or Equal To |

< | Is Less Than |

<= | Is Less Than Or Equal To |

and | Logical And |

or | Logical Or |

## For

Maple has a for loop construction, just like every other language. The syntax is a bit different, however.forYou will find this to be fairly intuitive.variablefromexpressiontoexpressiondostatement sequenceend do;

for i from 1 to 10
x[i] := i:
end do;
y := 0:
for j from x[3] to x[3]^2 do
y := y+j:
end do;
the_answer_to_life_the_universe_and_everything:=y;
*the_answer_to_life_the_universe_and_everything*:=42

Note that the task of the first loop could have been done
more easily using

`x:=[seq(i,i=1..10)];`

Assignment C is posted.

The test solution is available.