Department of Mathematics

Math 300: Mathematical Computing

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.


The basic syntax is

if conditional then statement sequence;
elif conditional then statement sequence;
else statement sequence;
end if;
As always, the 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.

=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
andLogical And
orLogical Or


Maple has a for loop construction, just like every other language. The syntax is a bit different, however.
for variable from expression to expression do
statement sequence
end do;
You will find this to be fairly intuitive.

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

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.

Department of Mathematics, PO Box 643113, Neill Hall 103, Washington State University, Pullman WA 99164-3113, 509-335-3926, Contact Us
Copyright © 1996-2020 Kevin Cooper