A few familiar themes tonight – the concept of looping is obviously common across every language, but some of the syntax in Swift is unique. Also familiar is that my late night approach to taking the tests following the videos leads to me making sloppy mistakes. Perhaps I should adjust my coronavirus lockdown schedule to allow me to focus on this earlier in the day with a fresher brain.
Feels like I should summarise at least one interesting tidbit from today’s lesson. I’ll go with named loops, used here to break out of the outer loop from the inner loop, something I haven’t seen in other languages.
outerLoop: for i in 1...10 {
for j in 1...10 {
let product = i * j
print ("\(i) * \(j) is \(product)")
if product == 50 {
print("It's a bullseye!")
break outerLoop
}
}
}
References
- Day 4 – https://www.hackingwithswift.com/100/swiftui/4
- Looping summary – https://www.hackingwithswift.com/sixty/4/8/looping-summary