Ruby - Create a traditional type of for loop


To create the traditional type of for loop, using a for loop to iterate over the values in a range.

For example, this is how to use a for loop variable to count up from 1 to 10, displaying its value at each turn through the loop:


for i in (1..10) do 
   puts( i ) 


A range expression such as 1..3 must be enclosed between parentheses when used with the each method.

Related Topic