Mega Code Archive

 
Categories / Ruby / Array
 

Use while and array index to get element from an array

array = ['cherry', 'strawberry', 'orange'] index = 0 while index < array.length   puts "At position #{index}: #{array[index]}"   index += 1 end