interview question-allocating memory block and breaking loop