How to write negative loop in ruby like for(i=index; i >= 0; i --)

前端 未结 7 1355
滥情空心
滥情空心 2020-12-25 10:42

How can I write a loop in Ruby that counts down, similar to the following C-style for loop?

for (i = 25; i >= 0; i--) { 
    print i;
}


        
相关标签:
7条回答
  • 2020-12-25 11:21

    Here's a simpler one:

    (0..25).reverse_each { |i| print i }
    
    0 讨论(0)
提交回复
热议问题