Home>

break statementThe break statement in the C programming language has two uses:

When a break statement is encountered in a loop, the loop terminates immediately,Program control continues after the loop statement (exit loop).

It can be used to terminate a case in a switch statement (in the next chapter).

If you use nested loops (that is, one loop over another), the break statement will stop the execution of the innermost loop,And start executing the code block after the next line of code block.

grammar

The syntax of a break statement in swift programming is as follows:

</p>
<p>
break
</p>
<p>

flow chart

Examples

import cocoa
var index=10
</p>
<p>
do {
 index=index + 1
 if (index == 15) {
 break
 }
 println ("value of index is \ (index)")
} while index<20
</p>
<p>

When the above code is compiled and executed,It produced the following results:

value of index is 11
value of index is 12
value of index is 13
value of index is 14

continue statementThe continue statement in the swift programming language tells the loop to stop executing statements,And start again at the next iteration of the loop.

For a for loop, the continue statement causes the conditional test and incremental portion of the loop to execute.For while and do ... while loops, the continue statement gives program control to conditional testing.

grammar

The syntax of the continue statement in swift is as follows:

</p>
<p>
continue
</p>
<p>

flow chart

Examples

import cocoa
var index=10
</p>
<p>
do {
 index=index + 1
 if (index == 15) {
 continue
 }
 println ("value of index is \ (index)")
} while index<20
</p>
<p>

When the above code is compiled and executed,It produced the following results:

value of index is 11
value of index is 12
value of index is 13
value of index is 14
value of index is 16
value of index is 17
value of index is 18
value of index is 19
value of index is 20
  • Previous Javascript-implemented multi-level context-sensitive menu effect code for provinces, cities, and counties nationwide
  • Next Solve the problem of 404 when js image is loaded