Swift offers several types of loops that can be used to execute a block of code repeatedly.
for-in
loop is used to iterate over a collection, such as an array or a range of numbers:main.swift72 chars4 lines
while
loop is used to execute a block of code repeatedly as long as a condition is true:main.swift77 chars4 lines
repeat-while
loop is similar to the while
loop, but the code inside the loop is always executed at least once:main.swift70 chars4 lines
Here's an example of using a for-in
loop to iterate over an array of numbers and print each one:
main.swift73 chars6 lines
gistlibby LogSnag