while loop depth first traversal