Swift Continue Statement

  Total Views : 335
  Comments : 0
  Keywords : Swift continue statement to stop what it is doing and jump to the start of next iteration of loop with examples, Stop code execution in swift using continue statement with examples

Here we will learn continue statement in swift with examples and how to use swift continue statement to stop executing the remaining code statements in loop and start the next iteration in loop.

Swift Continue Statement

In swift continue statement is used to stop executing the next statements in loop and start from the beginning of 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 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 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. 

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User