Ruby - Loop array using while loop and array length

Description

Loop array using while loop and array length

Demo

a = [1, "test", 2, 3, 4] 
i = 0 #   ww  w  . j  a v  a  2 s  .  c  o  m

while (i < a.length) 
   puts a[i].to_s + "X" 
   i += 1 
end

Result

Related Topic