/**
 * This exercise aims to practice creating empty lists and comparing them with other values.
 *
 * You need to create a function that takes two lists as arguments: list1 and list2.
 * The function should first create an empty list called "commonElements" to store the common elements found in both lists.
 *
 * Your task is to complete the code to find and add the common elements from list1 and list2 to "commonElements" list.
 * The function should return the final "commonElements" list.
 *
 * Remember, you should not use any built-in Kotlin functions to directly compare lists.
 *
 * Example:
 * ----------
 * Input:
 * list1 = listOf(1, 2, 3, 4, 5)
 * list2 = listOf(4, 5, 6, 7, 8)
 *
 * Output:
 * [4, 5]
 */
fun compareLists(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()  // Create an empty list to store the common elements

    for (element in list1) {
        if (element in list2 && element !in commonElements) {
            commonElements.add(element)  // Add common elements to the list
        }
    }

    return commonElements  // Return the final list
}
/**
 * This exercise aims to practice creating empty lists and comparing them with other values.
 *
 * You need to create a function that takes two lists as arguments: list1 and list2.
 * The function should first create an empty list called "commonElements" to store the common elements found in both lists.
 *
 * Your task is to complete the code to find and add the common elements from list1 and list2 to "commonElements" list.
 * The function should return the final "commonElements" list.
 *
 * Remember, you should not use any built-in Kotlin functions to directly compare lists.
 *
 * Example:
 * ----------
 * Input:
 * list1 = listOf(1, 2, 3, 4, 5)
 * list2 = listOf(4, 5, 6, 7, 8)
 *
 * Output:
 * [4, 5]
 */
fun compareLists(list1: List<Int>, list2: List<Int>): List<Int> {
/**
 * This exercise aims to practice creating empty lists and comparing them with other values.
 *
 * You need to create a function that takes two lists as arguments: list1 and list2.
 * The function should first create an empty list called "commonElements" to store the common elements found in both lists.
 *
 * Your task is to complete the code to find and add the common elements from list1 and list2 to "commonElements" list.
 * The function should return the final "commonElements" list.
 *
 * Remember, you should not use any built-in Kotlin functions to directly compare lists.
 *
 * Example:
 * ----------
 * Input:
 * list1 = listOf(1, 2, 3, 4, 5)
 * list2 = listOf(4, 5, 6, 7, 8)
 *
 * Output:
 * [4, 5]
 */
fun compareLists(list1: List<Int>, list2: List<Int>): List<Int> {

    val commonElements = mutableListOf<Int>()  // Create an empty list to store the common elements

    for (element in list1) {
        if (element in list2 && element !in commonElements) {
            commonElements.add(element)  // Add common elements to the list
        }
    }

    return commonElements  // Return the final list
}