Ruby の「continue」に相当する質問

Ruby の「continue」に相当する質問

continueC や他の多くの言語には、ループ内で使用するとループの次の反復にジャンプするキーワードがあります。Rubycontinueにはこのキーワードに相当するものはありますか?

ベストアンサー1

はい、 といいますnext

for i in 0..5
   if i < 2
     next
   end
   puts "Value of local variable is #{i}"
end

出力は次のようになります。

Value of local variable is 2
Value of local variable is 3
Value of local variable is 4
Value of local variable is 5
 => 0..5 

おすすめ記事