在 C 和许多其他语言中,有一个 continue
关键字,当在循环内部使用时,它会跳转到循环的下一次迭代。 Ruby 中是否有与此 continue
关键字等效的关键字?
最佳答案
是的,它叫做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
关于ruby - 相当于 Ruby 中的 "continue",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4010039/