Sometimes we work with a data that we didn't know the exact value or how many the elements of the array has.
This code below will do the same thing like what you want, but this one you don't need to know how many the elements of the array has, but will always print the data in element 0 and the next nth element after "that"("that" = 0). I give example for 20 elements below, but try to change it into different elements, and it will still printing the 0 element and every nth element after "that"("that" = 0).
ary = ["a","b","c","d","e","f",'g','h','i','j','k','l','m','n','o','p','q','r', 's', 't','u', 'v', 'w', 'x',]starter_index = 0 # your starter element to be printednth = 5 # the nth range element between each data to be printed (ary.size/nth + 1).times do |i| p ary[starter_index+ nth*i] unless ary[starter_index + nth*i].nil? endMaybe there's a better way to do this but I can't find out how.
And Sixth has a point, you stated for every 5th(yet from what parameter?) if 5th of array then so it should be 0, 4, 9, 14, 19, like Sixth said, but if 5th from the starter element to be printed you are right 0,5,10,15 because 5th after 0 is 1,2,3,4,5. My code used for the later, which is 5th from the starter(which is 0 or whatever you set in the starter_index variable).
@Sixth` so the index of 5 would be 6 elements away from the first index.
That is not correct, first index is 0, so from 0 to 5 is 5. But index of 5 is yes the 6th element of the array