/**
 * Given two sets, return their intersection as a new set using for loops.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return A new set containing the intersection of set1 and set2.
 *
 * Example:
 * val set1 = setOf(1, 2, 3, 4, 5)
 * val set2 = setOf(4, 5, 6, 7, 8)
 * intersectionSetsForLoops(set1, set2) // Output: [4, 5]
 */
fun intersectionSetsForLoops(set1: Set<Int>, set2: Set<Int>): Set<Int> {

    val intersection = mutableSetOf<Int>() // Initializing an empty set to store the intersection

    // Loop through each element in set1
    for (element in set1) {
        // Check if the element is present in set2
        for (anotherElement in set2) {
            // If the element is found in both sets, add it to the intersection set
            if (element == anotherElement) {
                intersection.add(element)
                break // Stop searching in set2 as the match is found
            }
        }
    }

    return intersection
}
/**
 * Given two sets, return their intersection as a new set using for loops.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return A new set containing the intersection of set1 and set2.
 *
 * Example:
 * val set1 = setOf(1, 2, 3, 4, 5)
 * val set2 = setOf(4, 5, 6, 7, 8)
 * intersectionSetsForLoops(set1, set2) // Output: [4, 5]
 */
fun intersectionSetsForLoops(set1: Set<Int>, set2: Set<Int>): Set<Int> {
/**
 * Given two sets, return their intersection as a new set using for loops.
 *
 * @param set1 The first set.
 * @param set2 The second set.
 * @return A new set containing the intersection of set1 and set2.
 *
 * Example:
 * val set1 = setOf(1, 2, 3, 4, 5)
 * val set2 = setOf(4, 5, 6, 7, 8)
 * intersectionSetsForLoops(set1, set2) // Output: [4, 5]
 */
fun intersectionSetsForLoops(set1: Set<Int>, set2: Set<Int>): Set<Int> {

    val intersection = mutableSetOf<Int>() // Initializing an empty set to store the intersection

    // Loop through each element in set1
    for (element in set1) {
        // Check if the element is present in set2
        for (anotherElement in set2) {
            // If the element is found in both sets, add it to the intersection set
            if (element == anotherElement) {
                intersection.add(element)
                break // Stop searching in set2 as the match is found
            }
        }
    }

    return intersection
}