error in if solved
while statements
added 'for' and corrected 'while'