/**
 * This exercise requires the completion of a Kotlin function that finds the intersection
 * of two sets and utilizes a while loop to iterate through the elements.
 *
 * @param s1 The first set.
 * @param s2 The second set.
 * @return The intersection of the two input sets.
 */
fun intersectionOfSetsAndWhileLoops(s1: Set<Any>, s2: Set<Any>): Set<Any> {

    // Initialize an empty set to store the common elements
    val result = mutableSetOf<Any>()

    // Create a copy of s1 to iterate through while maintaining the original set
    val s1Copy = s1.toMutableSet()

    // Iterate through each element of s1
    while (s1Copy.isNotEmpty()) {
        // Remove an element from s1Copy and assign it to current
        val current = s1Copy.first()
        s1Copy.remove(current)

        // Check if the element is also present in s2
        if (current in s2) {
            // Add the element to the result set
            result.add(current)
        }
    }

    return result
}
/**
 * This exercise requires the completion of a Kotlin function that finds the intersection
 * of two sets and utilizes a while loop to iterate through the elements.
 *
 * @param s1 The first set.
 * @param s2 The second set.
 * @return The intersection of the two input sets.
 */
fun intersectionOfSetsAndWhileLoops(s1: Set<Any>, s2: Set<Any>): Set<Any> {
/**
 * This exercise requires the completion of a Kotlin function that finds the intersection
 * of two sets and utilizes a while loop to iterate through the elements.
 *
 * @param s1 The first set.
 * @param s2 The second set.
 * @return The intersection of the two input sets.
 */
fun intersectionOfSetsAndWhileLoops(s1: Set<Any>, s2: Set<Any>): Set<Any> {

    // Initialize an empty set to store the common elements
    val result = mutableSetOf<Any>()

    // Create a copy of s1 to iterate through while maintaining the original set
    val s1Copy = s1.toMutableSet()

    // Iterate through each element of s1
    while (s1Copy.isNotEmpty()) {
        // Remove an element from s1Copy and assign it to current
        val current = s1Copy.first()
        s1Copy.remove(current)

        // Check if the element is also present in s2
        if (current in s2) {
            // Add the element to the result set
            result.add(current)
        }
    }

    return result
}