added while loop method