Loops
In programming, you frequently need to do the same thing repeatedly. For example, each month, a company will need to generate payroll slips for each employee. If the company has 10,000 employees, it would be inefficient to write 10,000 instructions to create payroll slips. Repeating a single instruction 10,000 times would be better, and loops are used for this.There are three loop types: the for-in loop, the while loop, and the repeat-while loop. The for-in loop will repeat a known number of times, and the while and repeat-while loops will repeat if the loop condition is true.
For more information on loops, visit https://docs.swift.org/swift-book/documentation/the-swift-programming-language/controlflow.
Let’s look at each type in turn.
for-In loops
The for-in loop steps through every value in a sequence, and a set of statements in curly braces, known as the loop body, is executed each time. Each value is assigned to a temporary variable in turn, and the temporary variable...