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.
Share With Friend
Have a friend to whom you would want to share this course?
Download LearnVern App
Download the app
Learn anywhere on the go
Get regular updates about your enrolled or new courses
Share content with your friends
Evaluate your progress through practice tests
No internet connection needed
Enroll for the webinar and join at the time of the webinar from anywhere
Enjoying this course!
All the Courses on Learnvern are Free! So Register/Sign in to
have Access all the Courses and Videos.