/**
 * This exercise requires the implementation of a function that calculates the intersection of two lists
 * and returns a list containing the common elements present on both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements from list1 and list2.
 *
 * Example:
 * iterListIntersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun iterListIntersection(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    
    // Iterate over every element in list1
    for (item1 in list1) {
        // Iterate over every element in list2
        for (item2 in list2) {
            // Check if the two elements are equal
            if (item1 == item2) {
                // Add the common element to the commonElements list
                commonElements.add(item1)
            }
        }
    }
    
    // Return the list containing the common elements
    return commonElements
}
/**
 * This exercise requires the implementation of a function that calculates the intersection of two lists
 * and returns a list containing the common elements present on both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements from list1 and list2.
 *
 * Example:
 * iterListIntersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun iterListIntersection(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This exercise requires the implementation of a function that calculates the intersection of two lists
 * and returns a list containing the common elements present on both lists.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A list containing the common elements from list1 and list2.
 *
 * Example:
 * iterListIntersection(listOf(1, 2, 3, 4, 5), listOf(4, 5, 6, 7, 8)) // [4, 5]
 */
fun iterListIntersection(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()
    
    // Iterate over every element in list1
    for (item1 in list1) {
        // Iterate over every element in list2
        for (item2 in list2) {
            // Check if the two elements are equal
            if (item1 == item2) {
                // Add the common element to the commonElements list
                commonElements.add(item1)
            }
        }
    }
    
    // Return the list containing the common elements
    return commonElements
}