在C和许多其他语言中,有一个continue关键字,当在循环中使用时,它会跳转到循环的下一次迭代。在Ruby语言中有没有这个continue关键字的等价物?
发布于 2010-10-25 03:41:09
是的,它叫做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 发布于 2010-10-25 03:41:59
next
另外,看看重做当前迭代的redo。
发布于 2012-06-26 01:50:56
https://stackoverflow.com/questions/4010039
复制相似问题