Skip to main content

Focused $Order Loops

In the $Order loop, set ln = "", means “start at the beginning of the last names”. Similarly, quit:(ln = "") means “stop at the end of the last names”. You can modify either statement to focus this loop to produce fewer subscripts. If you set 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 (“Jone”, for example), you will set ln equal to the substring to start. You also need to alter the Quit 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. The simpleloop.mac code:

simpleloop ; loop through last names
    set ln = ""
    for {
        set ln = $order( ^PersonI("Name", ln) )
        quit:(ln = "")
        write !, ln
        }
FeedbackOpens in a new tab