I am reading the book, Professional Swift by Michael Dippery @ 2015. And in the book, on page 25, he writes:
"Both break and continue statements break out of the innermost loops. However, you can label loops, which enables you to break out of an outer loop instead"
let data = [[3,9,44],[52,78,6],[22,91,35]]
let searchFor = 78
var foundVal = false
outer: for ints in data {
inner: for val in ints {
if val == searchFor {
foundVal = true
break outer
}
}
}
if foundVal {
print("Found \(searchFor) in \(data)")
} else {
print("Could not find \(searchFor) in \(data)")
}
however, in playground when I change:
break outer
code to
break inner
The same result occurs:
Found 78 in [[3, 9, 44], [52, 78, 6], [22, 91, 35]]
Is it still necessary to label loops
to break out of an outer loop
?