/**
 * Write a function that finds the intersection of two lists using nested loops.
 *
 * Given two lists, find the common elements (intersection) between them using nested loops.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list containing the common elements between the two lists.
 *
 * Example:
 * '``
 * val list1 = listOf(2, 4, 6, 8)
 * val list2 = listOf(2, 3, 4, 5)
 * println(intersectionOfAdvantagesAndNestedForLoops(list1, list2)) // [2, 4]
 * '``
 */
fun intersectionOfAdvantagesAndNestedForLoops(list1: List<Int>, list2: List<Int>): List<Int> {

    val intersection = mutableListOf<Int>()

    for (num1 in list1) {
        for (num2 in list2) {
            if (num1 == num2 && num1 !in intersection) {
                intersection.add(num1)
            }
        }
    }

    return intersection
}
/**
 * Write a function that finds the intersection of two lists using nested loops.
 *
 * Given two lists, find the common elements (intersection) between them using nested loops.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list containing the common elements between the two lists.
 *
 * Example:
 * '``
 * val list1 = listOf(2, 4, 6, 8)
 * val list2 = listOf(2, 3, 4, 5)
 * println(intersectionOfAdvantagesAndNestedForLoops(list1, list2)) // [2, 4]
 * '``
 */
fun intersectionOfAdvantagesAndNestedForLoops(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * Write a function that finds the intersection of two lists using nested loops.
 *
 * Given two lists, find the common elements (intersection) between them using nested loops.
 *
 * @param list1 The first list.
 * @param list2 The second list.
 * @return A new list containing the common elements between the two lists.
 *
 * Example:
 * '``
 * val list1 = listOf(2, 4, 6, 8)
 * val list2 = listOf(2, 3, 4, 5)
 * println(intersectionOfAdvantagesAndNestedForLoops(list1, list2)) // [2, 4]
 * '``
 */
fun intersectionOfAdvantagesAndNestedForLoops(list1: List<Int>, list2: List<Int>): List<Int> {

    val intersection = mutableListOf<Int>()

    for (num1 in list1) {
        for (num2 in list2) {
            if (num1 == num2 && num1 !in intersection) {
                intersection.add(num1)
            }
        }
    }

    return intersection
}