A two-dimensional array is just an array of arrays, so just use payroll.lengthto get the height and payroll[0].lengthto get the width (assuming all rows have the same width). Here's what your loop looks like using this idea:
for i in 0..payroll.length - 1
for j in 0..payroll[i].length - 1
puts payroll[i][j]
end
end
- . for each.with_index ( each_with_index, Ruby each.with_index):
payroll.each.with_index do |row, i|
row.each.with_index do |cell, j|
puts payroll[i][j]
end
end
, , , :
payroll.each do |row|
row.each do |cell|
puts cell
end
end