Loop N Times

I find myself doing "repeat N" imperative programming quite often, mainly in two different scenarios:

  1. Advent of Code, where many of the puzzles involve calculating one number, then using that number to process other data, repeatedly.
  2. Writing tests, particularly UI tests. Often you want to write tests like "hit the button five times to fill the form" or "hit the button fifty times to overflow the debouncer".

Perhaps Github should be surveyed to find out how many have invented their own "loop N times" functions, as was done when standardising Result was first discussed.

1 Like

Hello, just digged up a very old Swift 2.3 project. I had to make the following changes in order to resolve the error: C-style for statement has been removed in Swift 3

        /// SWIFT v2.3
        for var i = 1; i < 8; i+=1 {
            print("i: \(i)")
        }


        /// SWIFT 5
        for var i in  0..<8  {
            print("i: \(i)")
        }