# Using 'each' to print chunks of an array

Working through Day 2 of Ruby in "7 Languages in 7 Weeks" - the answer to the second question seems acceptable, the first one feels quite wrong. Any suggestions?

1. Print the contents of an array of sixteen numbers, four numbers at a time, using just each.

group = 0

(1..16).each do |x|
print x
group = group + 1
if group % 4 == 0
puts
group = 0
end
end

2. Now, do the same with each_slice in Enumerable (copied directly from http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-each_slice)

(1..16).each_slice(4) {|x| p x}

-
(1..16) is not an array. Besides using each, the first solution uses print and puts from the Kernel class, and % and +from Numeric. This book is not for me. –  steenslag Feb 28 '12 at 22:55
steenslag: Those are just my attempts at answers :) Could you clarify your point a bit more perhaps with an example? –  Jedidja Mar 1 '12 at 18:02

No need to save group x already saving it.
(1..16).each do |x|