Syntax for a for loop in ruby

前端 未结 10 1055
梦如初夏
梦如初夏 2020-12-02 07:20

How do I do this type of for loop in Ruby?

for(int i=0; i
10条回答
  •  庸人自扰
    2020-12-02 07:39

    The equivalence would be

    for i in (0...array.size)
    end
    

    or

    (0...array.size).each do |i|
    end
    

    or

    i = 0
    while i < array.size do
       array[i]
       i = i + 1 # where you may freely set i to any value
    end
    

提交回复
热议问题