def depthfirsttraversal(index, visitvertex):
    """Visit the vertexes of index in a depth-first traversal.
    The traversal is abandoned if visitvertex(it) returns False
    for any vertex."""
    it = index.topdownhistory()
    it.goBegin()
    while not it.atEnd and visitvertex(it):
        it.goNext()
    return it