/**
 * Chef has prepared a list of ingredients for a special dish. However, there are some undesirable ingredients he wants to remove from the list.
 * Your task is to help the chef by writing a Kotlin function that removes the undesirable ingredients from the list and stops the execution of the loop once all the specified ingredients have been removed.
 *
 * @param chefIngredients The list of all the ingredients prepared by the chef.
 * @param undesirableIngredients The list of ingredients that should be removed from the chef's list.
 * @return The updated list of ingredients after removing the undesirable ingredients.
 */
fun removeIngredients(chefIngredients: MutableList<String>, undesirableIngredients: List<String>): List<String> {

    val iterator = chefIngredients.iterator()
    while (iterator.hasNext()) {
        val ingredient = iterator.next()
        for (undesirableIngredient in undesirableIngredients) {
            if (ingredient == undesirableIngredient) {
                iterator.remove()
                undesirableIngredients.toMutableList().remove(undesirableIngredient) // Remove the ingredient from the undesirableIngredients list
            }
        }
        if (undesirableIngredients.isEmpty()) { // Break out of the loop if all undesirable ingredients have been removed
            break
        }
    }
    return chefIngredients
}

// Example usage
/**
 * Chef has prepared a list of ingredients for a special dish. However, there are some undesirable ingredients he wants to remove from the list.
 * Your task is to help the chef by writing a Kotlin function that removes the undesirable ingredients from the list and stops the execution of the loop once all the specified ingredients have been removed.
 *
 * @param chefIngredients The list of all the ingredients prepared by the chef.
 * @param undesirableIngredients The list of ingredients that should be removed from the chef's list.
 * @return The updated list of ingredients after removing the undesirable ingredients.
 */
fun removeIngredients(chefIngredients: MutableList<String>, undesirableIngredients: List<String>): List<String> {
/**
 * Chef has prepared a list of ingredients for a special dish. However, there are some undesirable ingredients he wants to remove from the list.
 * Your task is to help the chef by writing a Kotlin function that removes the undesirable ingredients from the list and stops the execution of the loop once all the specified ingredients have been removed.
 *
 * @param chefIngredients The list of all the ingredients prepared by the chef.
 * @param undesirableIngredients The list of ingredients that should be removed from the chef's list.
 * @return The updated list of ingredients after removing the undesirable ingredients.
 */
fun removeIngredients(chefIngredients: MutableList<String>, undesirableIngredients: List<String>): List<String> {

    val iterator = chefIngredients.iterator()
    while (iterator.hasNext()) {
        val ingredient = iterator.next()
        for (undesirableIngredient in undesirableIngredients) {
            if (ingredient == undesirableIngredient) {
                iterator.remove()
                undesirableIngredients.toMutableList().remove(undesirableIngredient) // Remove the ingredient from the undesirableIngredients list
            }
        }
        if (undesirableIngredients.isEmpty()) { // Break out of the loop if all undesirable ingredients have been removed
            break
        }
    }
    return chefIngredients
}

// Example usage