Skip to main content

Ending Focused Traverse Loops

Now let's focus the end of the loop. Again, assume the variable substr holds the non-empty substring. Then the following statement: (if left(ln ,len(sub)) <> substr then exit do) means: “if the beginning of ln doesn't match substr, then stop looping”. It also handles the case where Traverse() reaches the end of the names, where ln = "". That's because, if ln is the empty string, Mid() of ln is the empty string, and since substr isn't empty, the loop ends. Some examples are below.


println "first test: "
substr = "J" : ln = "Jones"
if left(ln, len(substr)) <> substr then println "No Match"
println "second test: "
substr = "J" : ln = "Swoboda"
if left(ln, len(substr)) <> substr then println "No Match"
println "third test: "
substr = "J" : ln = ""
if left(ln, len(substr)) <> substr then println "No Match"

substr = "J"
ln = traverse( ^PersonI("Name", substr), -1)
do
    ln = traverse( ^PersonI("Name", ln) )
    if left(ln, len(substr)) <> substr then exit do
    println ln
loop

The example code is in the loopend subroutine of BAStraverse.BAS. Run it—passing the substr—using the Terminal.


SAMPLES>do loopend^BAStraverse("J")
SAMPLES>do loopend^BAStraverse("Jones")

FeedbackOpens in a new tab