4.16 Loops

Oz provides a nice syntax for loops even though thses can be easilly expressed by recursion. The full beauty of loops will be discuss in Chapter on Loops. Here we only give a simple example related to working with lists.

Loops are useful if one wants to do something for all elements of a list. For instance, we might want to show all elements of a list:

declare proc{InspectAll List}

           for X in List do {Inspect X} end
        end
{InspectAll [5 4 3 2 1]}

We leave it as an execise to the reader to write a recurse program that does the same but without any loop. This becomes quite easy with using pattern matching conditionals that we discuss in the next section.


Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)