traverse using while and for loop