Break out of multiple loops
Code
func breakMultipleLoops(_ numbers: ClosedRange<Int>, _ value: Int) {
outerLoop: for number1 in numbers {
for number2 in numbers {
if number1 == number2 && number1 * number2 == value {
print("Square found: \(number1)")
break outerLoop
}
}
print("number: \(number1)")
}
}
Example
Output
number: 1
number: 2
number: 3
number: 4
number: 5
number: 6
number: 7
number: 8
number: 9
number: 10
number: 11
Square found: 12
Let's grow together 🌱
Cheers 🍻