ruby - 相当于 Ruby 中的 "continue"

标签 ruby keyword 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 

关于ruby - 相当于 Ruby 中的 "continue",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4010039/

相关文章:

c# - 为什么在 OOP(例如 Java、C#)中使用 break/continue 标签是一种不好的做法?

Ruby 运算符优先级

ruby-on-rails - 按姓氏组织联系人以按字母顺序排列的列表中显示

`restrict` 关键字只能在函数定义中使用吗?

Java,根据关键字对多维数组进行排序

internet-explorer - OpenCart - 如果填写产品 SEO 关键字,OpenCart 在 IE 上崩溃

c# - 如何在 while 循环中跳过多次迭代

java - 休息;然后继续;在 java

ruby - 如何访问散列的键作为对象属性

ruby - 为什么 Ruby 需要 .call 来调用 Proc?