While loop with array length : while « Statement « Ruby






While loop with array length


a = [1, "test", 2, 3, 4]
i = 0

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

 








Related examples in the same category

1.Here's the formal specification for the while loop:
2.The while Loop
3.Another form you can use is with begin/end
4.The while loop executes its contained code while a condition that you specify remains true.
5.loop code based on the result of a comparison made on each loop
6.use while loop to convert elements in an array to capitalized case
7.Replace one array with another