简体   繁体   中英

How would I do this type of for loop in ruby?

for(var i = 0; i < 200000; i += 50){
    // Do Stuff
}

The only way I can think to do it is to do the following

arr = [0,50,100,...,200000]
arr.each do |i|
    // Do Stuff
end

If that is in fact the only way. How could you build that array quickly?

(0..200000).step(50) do |i|
  # Do stuff
end

You can look at the full documentation .

(0...200000).step(50) do |i|
  # Do stuff
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM