Chapter 13 : Swift Loops



Sometimes we need to execute a piece of code several time.

For example if need to print counting from 1,2….100 then instead of writing print statement 100 times we prefer to add a loop of for and print in a single line.

We have below loops statement to be used in swift

for-in : This loop is used for executing a set of statements for each item in a range , collection or progression.

while loop  : This statement is used while a given condition is true. It tests the condition before executing the loop body.

repeat while loop : It is similar to while loop, the only difference is it test the condition at the end of the loop body.

All loops have its control statements as well, below are the control statement for loops

continue statement

Used to stop the loop and start again at the beginning of the next iteration in the loop

break statement

Used to terminate the loop statement

fall through statement

Used to simulates the behaviour of swift4 to C-style switch



Add a Comment

Your email address will not be published. Required fields are marked *