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 #   w  w w . ja va 2 s .com

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

Result

Related Topic