/**
 * This exercise requires you to write a function that counts the number of times a given target element appears in a list of elements using a loop.
 *
 * Write a function that takes in two arguments:
 * - elements: a list of elements (can contain duplicates)
 * - target: the element you want to count occurrences of
 *
 * Your function should return an integer representing the count of occurrences of the target element in the given list.
 *
 * You must solve the exercise using a loop (e.g., for or while loop) without using any built-in Kotlin functions or methods, such as count(), that automatically handle this task.
 *
 * Example:
 * countElementsWithLoop(listOf(1, 2, 2, 3, 4, 5, 2), 2)
 * Output: 3
 *
 * Note: You are not allowed to use the 'count()' method or any other pre-existing function that directly counts occurrences.
 */
fun countElementsWithLoop(elements: List<Int>, target: Int): Int {

    var count = 0

    // Use a loop to iterate through each element in the list
    for (element in elements) {
        if (element == target) {
            count++
        }
    }

    return count
}
/**
 * This exercise requires you to write a function that counts the number of times a given target element appears in a list of elements using a loop.
 *
 * Write a function that takes in two arguments:
 * - elements: a list of elements (can contain duplicates)
 * - target: the element you want to count occurrences of
 *
 * Your function should return an integer representing the count of occurrences of the target element in the given list.
 *
 * You must solve the exercise using a loop (e.g., for or while loop) without using any built-in Kotlin functions or methods, such as count(), that automatically handle this task.
 *
 * Example:
 * countElementsWithLoop(listOf(1, 2, 2, 3, 4, 5, 2), 2)
 * Output: 3
 *
 * Note: You are not allowed to use the 'count()' method or any other pre-existing function that directly counts occurrences.
 */
fun countElementsWithLoop(elements: List<Int>, target: Int): Int {
/**
 * This exercise requires you to write a function that counts the number of times a given target element appears in a list of elements using a loop.
 *
 * Write a function that takes in two arguments:
 * - elements: a list of elements (can contain duplicates)
 * - target: the element you want to count occurrences of
 *
 * Your function should return an integer representing the count of occurrences of the target element in the given list.
 *
 * You must solve the exercise using a loop (e.g., for or while loop) without using any built-in Kotlin functions or methods, such as count(), that automatically handle this task.
 *
 * Example:
 * countElementsWithLoop(listOf(1, 2, 2, 3, 4, 5, 2), 2)
 * Output: 3
 *
 * Note: You are not allowed to use the 'count()' method or any other pre-existing function that directly counts occurrences.
 */
fun countElementsWithLoop(elements: List<Int>, target: Int): Int {

    var count = 0

    // Use a loop to iterate through each element in the list
    for (element in elements) {
        if (element == target) {
            count++
        }
    }

    return count
}