Sequences have a beginning, an end, and a method for producing subsequent values in the sequence. The range operators ".." and "..." are used by Ruby to produce these sequences. The two-dot form creates a range that includes the provided high number, but the three-dot form creates a range that excludes it.
The range() function returns a number series that starts at 0 and increments by 1 (by default) before stopping at a specified value.
In a for loop, one of the most typical uses of the range() function is to iterate through a series of variables. This is very useful if you want to access all of the values in a list or array, or just every other item, for example. The range() method generates a series from 0 to 4 in this example.
Benefits of using Range Operators
It is easy to find out how much space is left in an array.
It is easy to find out how many items are in an array.
It is easy to iterate through the elements of an array and perform some operations on each element.