Day 4

100 Days of SwiftUI

Finished up Day 4. All of about loops.

Learned how to label an outside loop so we can exit nested loops at the level that we choose.

outerLoop: for i in 1...10 {
    for j in 1...10 {
        let product = i * j
        print ("\(i) * \(j) is \(product)")
    }
}

We can then set a condition in the inner loop to break out of both loops.

outerLoop: for i in 1...10 {
    for j in 1...10 {
        let product = i * j
        print ("\(i) * \(j) is \(product)")

        if product == 73 {
            print("It's Sheldon's favorite number!")
            break outerLoop
        }
    }
}

If we did not break out of “outerloop”, the inner loop would break and the outer loop would continue to run.