Looping through an array with step

后端 未结 7 1065
余生分开走
余生分开走 2020-12-05 23:24

I want to look at every n-th elements in an array. In C++, I\'d do this:

for(int x = 0; x

        
7条回答
  •  感情败类
    2020-12-06 00:09

    Just use step() method from Range class which returns an enumerator

    (1..10).step(2) {|x| puts x}
    

提交回复
热议问题