/**
 * This function takes two lists as input and returns a new list containing
 * the intersection of elements from both lists.
 *
 * @param list1 The first list containing integers
 * @param list2 The second list containing integers
 * @return A list containing the intersection of elements from list1 and list2
 */
fun intersectionNestedLoopsIteration(list1: List<Int>, list2: List<Int>): List<Int> {

    // Initialize an empty list to store the intersection
    val intersection = mutableListOf<Int>()

    // Iterate over each element in list1
    for (i in list1) {
        // Iterate over each element in list2
        for (j in list2) {
            // Check if the current element from list1 exists in list2
            if (i == j) {
                // Append the element to the intersection list
                intersection.add(i)
                // Break out of the inner loop to avoid redundant elements
                break
            }
        }
    }

    return intersection
}
/**
 * This function takes two lists as input and returns a new list containing
 * the intersection of elements from both lists.
 *
 * @param list1 The first list containing integers
 * @param list2 The second list containing integers
 * @return A list containing the intersection of elements from list1 and list2
 */
fun intersectionNestedLoopsIteration(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This function takes two lists as input and returns a new list containing
 * the intersection of elements from both lists.
 *
 * @param list1 The first list containing integers
 * @param list2 The second list containing integers
 * @return A list containing the intersection of elements from list1 and list2
 */
fun intersectionNestedLoopsIteration(list1: List<Int>, list2: List<Int>): List<Int> {

    // Initialize an empty list to store the intersection
    val intersection = mutableListOf<Int>()

    // Iterate over each element in list1
    for (i in list1) {
        // Iterate over each element in list2
        for (j in list2) {
            // Check if the current element from list1 exists in list2
            if (i == j) {
                // Append the element to the intersection list
                intersection.add(i)
                // Break out of the inner loop to avoid redundant elements
                break
            }
        }
    }

    return intersection
}