Latest web development tutorials

Swift Continue statement

Swift cycle Swift cycle

Swift continue statement tells a loop iteration immediately stop this cycle and start again the next iteration.

For thefor loop,continue increment statement after executing the statement will still be executed. Forwhile and do ... whileloop, continue to re-execute the statement conditional statement.

grammar

Swift continue statement syntax is as follows:

continue

flow chart:

C continue statement

Examples

import Cocoa
 
var index = 10

repeat{
   index = index + 1
	
   if( index == 15 ){ // index 等于 15 时跳过
      continue
   }
   print( "index 的值为 \(index)")
}while index < 20 

The above program execution output is:

index 的值为 11
index 的值为 12
index 的值为 13
index 的值为 14
index 的值为 16
index 的值为 17
index 的值为 18
index 的值为 19
index 的值为 20

Swift cycle Swift cycle