/**
 * This exercise requires finding the common elements between two lists using the AND Operator and iterating over
 * a specific range.
 *
 * Given two lists, list1 and list2, your task is to write a function that returns a new list containing the common
 * elements present in both lists.
 *
 * Example:
 * For list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8], the expected output is [4, 5] because these are the elements
 * that appear in both lists.
 *
 * You need to complete the code below to solve this exercise.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over the indices of list1
    for (element in list1) {
        // Check if the current element in list1 is present in list2
        if (element in list2) {
            // Add the common element to the commonElements list
            commonElements.add(element)
        }
    }

    return commonElements
}
/**
 * This exercise requires finding the common elements between two lists using the AND Operator and iterating over
 * a specific range.
 *
 * Given two lists, list1 and list2, your task is to write a function that returns a new list containing the common
 * elements present in both lists.
 *
 * Example:
 * For list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8], the expected output is [4, 5] because these are the elements
 * that appear in both lists.
 *
 * You need to complete the code below to solve this exercise.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This exercise requires finding the common elements between two lists using the AND Operator and iterating over
 * a specific range.
 *
 * Given two lists, list1 and list2, your task is to write a function that returns a new list containing the common
 * elements present in both lists.
 *
 * Example:
 * For list1 = [1, 2, 3, 4, 5] and list2 = [4, 5, 6, 7, 8], the expected output is [4, 5] because these are the elements
 * that appear in both lists.
 *
 * You need to complete the code below to solve this exercise.
 */
fun findCommonElements(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()

    // Iterate over the indices of list1
    for (element in list1) {
        // Check if the current element in list1 is present in list2
        if (element in list2) {
            // Add the common element to the commonElements list
            commonElements.add(element)
        }
    }

    return commonElements
}