Nested and while loop