You can use the + and – operators to add and remove items to a collection respectively, and to add and remove entire collections to and from each other. Some examples will help.

You can also use a “for each” block to loop over all of the items in a collection.

Example 1: Adding an item to a collection

In the following example we add a single item to the collection, and then use for-each to print each item in the collection.

Which of course prints out One, Two, Three, Four, Five.

Example 2: Removing an item from a collection

This example is almost the same, but instead of adding something to the collection, we instead remove the “Two” from the collection.

This code prints out One, Three, Four.

Example 3: Adding two collections together

In this example we create two collections.  Just for fun (I don’t get out much) I created the second collection by starting with an empty collection and then adding things to it individually.  Then we create a new collection called “everything” which is the union of the two collections.

If you guessed that the above code prints out One, Two, Three, Four, Five, Six then you win a prize!  Speaking of not getting out much: What has four legs and says “Boo”?  A cow with a cold!

Example 4: Removing one collection from the other

Here we take one collection and remove all the elements from a second collection. Notice that the second collection has an element that isn’t in the first collection (but that doesn’t matter).

This code prints out One, Two, Three.  Not Four.  Five is right out.

Function support

Many functions also support collections.  For example, see the documentation on random() and choose() for some interesting ideas on using collections.