在C和许多其他语言中,有一个continue
关键字,当在循环中使用时,它会跳转到循环的下一个迭代.在Ruby中是否有与这个continue
关键字等价的词?
在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