Swift-continue-statement

提供:Dev Guides
移動先:案内検索

Swift-ステートメントを続行

Swift 4の continue ステートメントは、実行中の処理を停止し、ループの次の反復の開始時に再び開始するようにループに指示します。

*for* ループの場合、 *continue* ステートメントは条件付きテストを実行し、実行するループの部分をインクリメントします。 *while* および *do ... while* ループの場合、 *continue* ステートメントにより、プログラム制御が条件付きテストに渡されます。

構文

Swift 4の continue ステートメントの構文は次のとおりです-

continue

流れ図

継続ステートメント

var index = 10

repeat {
   index = index + 1
   if( index == 15 ){
      continue
   }
   print( "Value of index is \(index)")
} while index < 20

上記のコードをコンパイルして実行すると、次の結果が生成されます-

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