## if then statements

There are basically two flavors'' of if then statements, similar to the MAPLE:

if {\it Boolean expression} then {\it statements} else {\it more statements} end if;


and

if {\it Boolean expression} then {\it statements} end if;


What is a Boolean expression''? It is usually a statement using the Boolean operators  x and y,  x or y,  x xor y,  not x,  x in S,  x eq y (for ),  x ne y (for ),  x ge y (for ),  x le y (for ), and a few others.

For example,

> if 2^5 eq 32  then
if> print "they're equal";
if> else print "no they're not";
if> end if;
they're equal


and

> if 2^5 in [1..31]  then k:=0; else k:=1; end if;
> k;
1


Exercise 6.9.14   First, initialize a sequence to be empty by typing L:=[];. Next, construct a for loop over a variable x in the set of integers given by which appends if it is odd.

Remark 6.9.15   In some cases, it appears that MAGMA wants you to type the if then'' statent on one line, the statements'' on the next line, and the end if'' on the last line. In other cases, having them all on one line is fine.

david joyner 2008-04-20