Skip to main content

Traverse() Function, continued

Traverse can also traverse subscripts in reverse order, using -1 for the second argument.

x(1)=1 : x(4)=2 : x(9)=3
println "last subscript is: ", traverse( x(""), -1 )
println "subscript before 9 is: ", traverse( x(9), -1 )
println "subscript before 4 is: ", traverse( x(4), -1 )
println "subscript before 1 is: ", traverse( x(1), -1 )

Often, when using Traverse() to get valid subscripts, you also want to retrieve the value stored on the right-hand side of the equals sign. If you supply a variable name as the third argument of Traverse(), you can do this in one step instead of two.

x(1)=1 : x(4)=2 : x(9)=3
a = traverse( x(4) ) : b = x(a)
println a, "   ", b ' get next subscript (a), and value on right (b)
a = traverse( x(4), 1, b)
println a, "   ", b ' do the same thing, simpler and faster
FeedbackOpens in a new tab