rubyのblock文中で、条件によって処理を飛ばすのにnextが使える。
#5を飛ばす
10.times{|v|
if v==5
next
end
puts v
}
#出力
#0
#1
#2
#3
#4
#6
#7
#8
#9
ちなみに、breakだと、ブロック処理全体を終了する。
10.times{|v|
if v==5
break
end
puts v
}
#出力結果
# 0
# 1
# 2
# 3
# 4
More than 5 years have passed since last update.
rubyのblock文中で、条件によって処理を飛ばすのにnextが使える。
#5を飛ばす
10.times{|v|
if v==5
next
end
puts v
}
#出力
#0
#1
#2
#3
#4
#6
#7
#8
#9
ちなみに、breakだと、ブロック処理全体を終了する。
10.times{|v|
if v==5
break
end
puts v
}
#出力結果
# 0
# 1
# 2
# 3
# 4
Register as a new user and use Qiita more conveniently