/**
 * This exercise aims to find the common elements between two lists by using short-circuiting and appending elements to a list.
 * In this exercise, you need to utilize short-circuiting by utilizing the 'and' operator to terminate the loop as soon as a common element is found.
 * Furthermore, you are required to append the common elements to a new list. Make sure to handle all possible edge cases and optimize your solution.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    if (list1.isEmpty() || list2.isEmpty()) {  // Check if either list is empty
        return commonElements
    }

    for (element1 in list1) {  // Iterate through elements in list1
        for (element2 in list2) {  // Iterate through elements in list2
            if (element1 == element2) {  // Check if elements are equal
                commonElements.add(element1)  // Append common element to the list
                break  // Terminate the inner loop using short-circuiting
            }
        }
    }

    return commonElements
}
/**
 * This exercise aims to find the common elements between two lists by using short-circuiting and appending elements to a list.
 * In this exercise, you need to utilize short-circuiting by utilizing the 'and' operator to terminate the loop as soon as a common element is found.
 * Furthermore, you are required to append the common elements to a new list. Make sure to handle all possible edge cases and optimize your solution.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {
/**
 * This exercise aims to find the common elements between two lists by using short-circuiting and appending elements to a list.
 * In this exercise, you need to utilize short-circuiting by utilizing the 'and' operator to terminate the loop as soon as a common element is found.
 * Furthermore, you are required to append the common elements to a new list. Make sure to handle all possible edge cases and optimize your solution.
 */
fun findCommonElements(list1: List<Any>, list2: List<Any>): List<Any> {

    val commonElements = mutableListOf<Any>()

    if (list1.isEmpty() || list2.isEmpty()) {  // Check if either list is empty
        return commonElements
    }

    for (element1 in list1) {  // Iterate through elements in list1
        for (element2 in list2) {  // Iterate through elements in list2
            if (element1 == element2) {  // Check if elements are equal
                commonElements.add(element1)  // Append common element to the list
                break  // Terminate the inner loop using short-circuiting
            }
        }
    }

    return commonElements
}