Use while loop in favor of forEach