This is very promising!
I have now expanded the example a bit, but unfortunately I’m not able to transfer this condition.
In this example I have a list of X-coordinates and a list of nodenumbers (x_unsorted1 and node_unsorted1).
Furthermore I have a list of sorted X-coordinates (X-sorted1). My example runs through both lists and finds the indices in the sorted list corresponding to the unsorted list. I then use this index number to sort a new list (node_sorted1) containing node numbers sorted by X-coordinates.
+prog template urs:66.1
head Endloop condition
let#x_unsorted1 1, 5, 3, 9, 8, 7, 4, 6, 2
let#node_unsorted1 11, 19, 16, 15, 14, 18, 12, 13, 17
let#x_sorted1 1, 2, 3, 4, 5, 6, 7, 8, 9
! output should be: 11 17 16 12 19 13 18 14 15
loop#i x_Sorted1
loop#j x_Unsorted1
if #x_Sorted1(#i) == #X_Unsorted1(#j)
let#X_id1(#i) #j
endif
prt#j
endloop !(#x_Sorted1(#i)-#X_Unsorted1(#j))
sto#node_sorted1(#i) #node_unsorted1(#X_id1(#i))
endloop
loop#i node_sorted1
let#prt #node_sorted1(#i)
prt#prt
endloop
end
OUTPUT:
25 ENDLOOP
---- CADINT VARIABLE PRT ( 0) = 11.00
---- CADINT VARIABLE PRT ( 0) = 17.00
---- CADINT VARIABLE PRT ( 0) = 16.00
---- CADINT VARIABLE PRT ( 0) = 12.00
---- CADINT VARIABLE PRT ( 0) = 19.00
---- CADINT VARIABLE PRT ( 0) = 13.00
---- CADINT VARIABLE PRT ( 0) = 18.00
---- CADINT VARIABLE PRT ( 0) = 14.00
---- CADINT VARIABLE PRT ( 0) = 15.00
26 END
So the function works as intended, but as it is now it runs through loop#j way too many times, and could be ended as soon as (#x_Sorted1(#i)-#X_Unsorted1(#j)) = 0 is met, but again it doesn’t seem to work as intended.
So how do I make this endloop condition work?