# 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)];`

The last test will take place at the final exam time on
Tuesday, 12 December, from 1:30-3:30. It will be written as a one-hour (not
50 minute) exam, but you may have the full two hours for it.
In other respects it will be very like the other tests, but
comprehensive - it will emphasize Python, but cover all the
topics we have seen.
There is a
Sample Exam, but be aware that things will have changed somewhat
with the advent of ChatGPT.

The scores are posted on the Info tab at
My.math.
Notify the instructor of discrepancies immediately.