Recap Exercise

In case you get stuck anywhere, don't be afraid to ask the coaches! They are here to help and will gladly explain everything to you!

Take notes during the exercises. Even if you never look at them again, they will help you memorise things!

For these exercises, you will use your editor (Visual Studio Code or similar).

First, create an empty file with a meaningful name for this exercise, for example iteration.rb. Note the file extension .rb! Also remember what folder you saved your file in. It makes sense to create a folder for each lesson of the course.

Then, use cd in the command line to change to that folder. When you run ls you should see your file there.

Now you can run your Ruby program with ruby iteration.rb in the command line.

Repeat the above steps and remember to save your file in the editor before running it!

With the following code you would normally iterate over an array:

places = ["Paris", "Nairobi", "Tokyo", "Portland"]
places.each do |a_place|
  puts "Place: #{a_place}"

Find a way to achieve the same output without using each. Instead try using a loop construct. Your code should also work with more or fewer elements in the places array.

Hint: You’ll have to access individual array elements using their integer index (i.e. places[index]).