added while loop with array function.