Looping is a fundamental concept in programming. In Swift, there are three types of loops: for-in
loop, while
loop, and repeat-while
loop.
The for-in
loop is used to iterate over a sequence such as an array, a range of numbers, or a string.
main.swift99 chars8 lines
The while
loop is used when you want to keep looping until a certain condition is met.
main.swift68 chars8 lines
The repeat-while
loop is similar to the while
loop, but the code block is executed at least once before the condition is checked.
main.swift75 chars8 lines
In all three types of loops, you can use the break
statement to exit the loop prematurely and the continue
statement to skip the current iteration and continue with the next iteration.
gistlibby LogSnag