相关疑难解决方法(0)

在Ruby早期逃避.each {}迭代

码:

 c = 0  
 items.each { |i|  
   puts i.to_s    
   # if c > 9 escape the each iteration early - and do not repeat  
   c++  
 }  
Run Code Online (Sandbox Code Playgroud)

我想抓住前10个项目,然后离开"每个"循环.

我该如何用?替换注释行?有更好的方法吗?更多Ruby惯用的东西?

ruby iterator loops enumerator

39
推荐指数
3
解决办法
5万
查看次数

标签 统计

enumerator ×1

iterator ×1

loops ×1

ruby ×1