The while Loop : while « Statement « Ruby






The while Loop



i = 0
breeds = [ "q", "ar", "ap", "p" ]
puts breeds.size # => 4
temp = []

while i < breeds.size do
  temp << breeds[i].capitalize
  i +=1
end

temp.sort!
breeds.replace( temp )
p breeds

 








Related examples in the same category

1.Here's the formal specification for the while loop:
2.Another form you can use is with begin/end
3.The while loop executes its contained code while a condition that you specify remains true.
4.While loop with array length
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