Skip to main content

Focused Traverse Loops

In the Traverse() loop below, ln = "", means “start at the beginning of the last names”. Similarly, if ln = "" then exit do means “stop at the end of the last names”. You can modify either statement to focus this loop to produce fewer subscripts. If you assign ln = "B", for example, this loop will skip over “Agee”.

If you want this loop to produce only the names starting with a substring of a name, you will set ln equal to the substring to start. You also need to alter the If statement so that the loop stops before it reaches names that start with letters after the substring. There are several ways to do this; the next page shows one approach.


ln = ""
do
    ln = traverse(^PersonI("Name", ln) )
    if ln = "" then exit do
    println ln
loop
FeedbackOpens in a new tab