/**
 * This exercise requires counting the animals on the farm and breaking out of a loop when a specific number of animals
 * has been counted.
 *
 * @param farmer The name of the farmer.
 * @param animals A list of animals on the farm.
 * @param totalAnimals The total number of animals the farmer wants to count.
 * @return The number of animals counted by the farmer before breaking out of the loop.
 *
 * Example:
 * countAnimals("John", listOf("cow", "dog", "horse", "sheep", "chicken"), 3)
 * Output: 3
 */
fun countAnimals(farmer: String, animals: List<String>, totalAnimals: Int): Int {

    // Initialize count variable to keep track of the number of animals counted
    var count = 0

    // Start enumerating the animals
    for ((idx, animal) in animals.withIndex()) {
        // Increment count by 1 each time an animal is counted
        count++

        // Print the name of the farmer and the current animal being counted
        println("$farmer is currently counting $animal...")

        // Check if the desired number of animals has been counted
        if (count == totalAnimals) {
            break
        }
    }

    return count
}
/**
 * This exercise requires counting the animals on the farm and breaking out of a loop when a specific number of animals
 * has been counted.
 *
 * @param farmer The name of the farmer.
 * @param animals A list of animals on the farm.
 * @param totalAnimals The total number of animals the farmer wants to count.
 * @return The number of animals counted by the farmer before breaking out of the loop.
 *
 * Example:
 * countAnimals("John", listOf("cow", "dog", "horse", "sheep", "chicken"), 3)
 * Output: 3
 */
fun countAnimals(farmer: String, animals: List<String>, totalAnimals: Int): Int {
/**
 * This exercise requires counting the animals on the farm and breaking out of a loop when a specific number of animals
 * has been counted.
 *
 * @param farmer The name of the farmer.
 * @param animals A list of animals on the farm.
 * @param totalAnimals The total number of animals the farmer wants to count.
 * @return The number of animals counted by the farmer before breaking out of the loop.
 *
 * Example:
 * countAnimals("John", listOf("cow", "dog", "horse", "sheep", "chicken"), 3)
 * Output: 3
 */
fun countAnimals(farmer: String, animals: List<String>, totalAnimals: Int): Int {

    // Initialize count variable to keep track of the number of animals counted
    var count = 0

    // Start enumerating the animals
    for ((idx, animal) in animals.withIndex()) {
        // Increment count by 1 each time an animal is counted
        count++

        // Print the name of the farmer and the current animal being counted
        println("$farmer is currently counting $animal...")

        // Check if the desired number of animals has been counted
        if (count == totalAnimals) {
            break
        }
    }

    return count
}