Ruby way

Do not use for loop

We have an array and we need to print the double of each item in the array.

We can do it in so many ways. First let’s see two different styles of using for loop.

We can also use the “for loop” a bit differently as shown below.

Using each is the best way

JavaScript and in other programming languages “for loops” are used a lot. However in Ruby the most preferred way of iterating through items in an array is by using each.