Swift Loops

Posted on Wed 12 February 2020 in swift

I'm stuck in a loop, doing day 4 of 100 Days of Swift again.

Only two short comments today.

First, I'd forgotten about repeat loops. Does anyone really use them?

repeat {
    print("The body of a repeat loop is always executed at least once.")
    break
} while true

Second, I also forgot about named loops and exiting multiple loops.

def getPixel(x: Int, y: Int) -> UIColor {
    // ... some implementation
}

columns: for i in 0...1125 {
    for j in 0...2436 {
        if getPixel(x: i, y: j) == .white {
            print("found the white pixel")
            break columns
        }
    }
}

Today, a Ulysses for iPad annoyance: why does Ulysses try to auto-capitalize text in a code block?