Retrieve the next Key-Value entry from the tree position indicated by the iterator, and return a new iterator for the next entry.
If the retrieved entry is the last one, Iter2 is the empty iterator []. The end of iteration can be determined either by testing the iterator for being [], or by the failure of iter_next when called with an empty iterator.
% Print all tree entries using recursion:
print_tree(Tree) :-
iter_init(Tree, It),
print_it(It).
print_it(It1) :-
( iter_next(It1, K, V, It2) ->
writeln(K-V),
print_it(It2)
;
true
).
% The same using a do-loop:
print_tree(Tree) :-
iter_init(Tree, It0),
( fromto(It0,It1,It2,[]) do
iter_next(It1, K, V, It2),
writeln(K-V)
).