Suppose you have a collection of facts stored in the database about people, their relations, their jobs, their possessions, etc. You can use a pattern to select items from the database. If you wish to find all the matching items, e.g. all the people who are teachers, then you can use foreach, e.g. using a form like this, which will perform some action on each person recorded as a teacher. It will therefore need to be declared as a variable.
Lets demonstrate with a database of information about some people.
You may find it convenient to put the following examples into a file of your own called something like database.p, or foreach.p. You can delete the file later on. You could extend this procedure with more examples of the same general kind, if you wish. That would certainly work, but would require more storage space, and would slightly slow down searching the database. We'll use this procedure every time we want to start off with a new database.