use a while loop to limit path.