Swift Continue Statement

In swift, the continue statement is used to stop executing the next statements in loop and start from the beginning of the next iteration of loop.

 

Generally in swift we use continue statement in loops to skip the execution of remaining code statements in loop and start the execution of next iteration of the loop.

Syntax of Swift Continue Statement

Following is the syntax of continue statement in a swift programming language.

 

continue

Now we will see how to use continue statement in swift programming language with examples.

Swift Continue Statement Example

Following is the example of continue statement in swift programming language.

 

var num = 3

while num < 40

{

num += 4

if (num % 2) == 0 {

continue

}

print("\(num)")

}

If you observe above example we are skipping the print of numbers in case if the given condition matches.

 

When we run the above code, swift playground will return the result like as shown below.

 

7

11

15

19

23

27

31

35

39

43

This is how we can use continue statement in swift programming language to skip the execution of statements in loop based on our requirements.