Use while loop to remove unused variable warning