Start a loop from 1

后端 未结 5 1526
南笙
南笙 2020-12-29 18:07

I recently came upon the scary idea that Integer.count loops in Ruby start from 0 and go to n-1 while playing with the Facebook Engine

5条回答
  •  一生所求
    2020-12-29 18:28

    There is of course the while-loop:

    i = 1
    while i<=10 do
      print "#{i} "
      i += 1
    end
    # Outputs: 1 2 3 4 5 6 7 8 9 10
    

提交回复
热议问题