| Start |
|---|
| For-in loop The for-in loop allows you to iterate over any sequence. Iterating over a rangeYou can iterate over both half-open and closed ranges: Iterating over an array or setIf you need the index for each element in the array, you can use the
In Swift 3, Iterating over a dictionaryIterating in reverseYou can use the In Swift 3, Iterating over ranges with custom strideBy using the In Swift 3, the |
For-in loop with filtering
By adding a
It's useful when you need to iterate only through the values that match some pattern: Also you can filter optional values and unwrap them if appropriate by adding |
| Sequence Type forEach block A type that conforms to the SequenceType protocol can iterate through it's elements within a closure: The same could also be done with a named parameter: *Note: Control flow statements (such as break or continue) may not be used in these blocks. A return can be called, and if called, will immediately return the block for the current iteration (much like a continue would). The next iteration will then execute. |
| Repeat-while loop Similar to the while loop, only the control statement is evaluated after the loop. Therefore, the loop will always execute at least once. |
| Breaking a loop A loop will execute as long as its condition remains true, but you can stop it manually using the Syntax
|
| Repeat-while loop Similar to the while loop, only the control statement is evaluated after the loop. Therefore, the loop will always execute at least once. |
Read Article
https://develop.horje.com/learn/1434/reference