**Writing functions**

A function in ISETL always has four components: the name of the
function, the list of input variables, the directions on how to produce an output, and an
end. Here is the syntax:

* Name* := func( *list of input
variables* );

* some commands, which
MUST include a *return *statement
* end;

For example, here is a function that computes and returns the distance between two values on a number line .

> F := func(x , y);

>> if x > y then return x - y;

>> else return y - x;

>> end;

>> end;

(This is, of course, the hard way. The calculation abs(x - y) does the same thing without using the if...else...end syntax.)

**Writing loops
**A loop is designed to do something over and over. In ISETL it always
has three components: the directions on what values to examine, the comands on what to do,
and the end. Here is the syntax:

for

For example, here is a loop that finds all the two-digit palindromes.

> for n in {10..99} do

>> if n div 10 = n mod 10 then print n; end;

>> end;

Notice the print command in this loop. If "print" is not included in the command, the computer will find all of the values but will not tell you what they are!

**Writing set formers and tuple formers
** A set is a collection of elements. One way to define a set in ISETL
is to list its elements within braces, and this works well for small sets. But larger sets
need a set former.

The expression tells what to put in the set, the domain tells where to look for it, and the condition tells which elements to include.

For example, here is a set former for the set of square roots of even two-digit
numbers.

> S := { sqrt(x) : x in {10..99} | even(x) };

ISETL will look at the values form 10 to 99, select the even numbers, and calculate the
square roots of those numbers. To see the result, you must ask for it by typing

> S;

Tuples are done the same way. The only difference is that tuples must stay in order, so
they need brackets in place of the braces. For example,

> [ 2*n**2 - n + 11 : n in [1..10] ];

will use the values 1 through 10 for the variable n and calculate the outputs from the
function 2*n**2-n+11. Notice that this tuple former did not use a condition.