Ruby does not support i++
syntax as a shortcut to i+=1
. See "Why doesn't Ruby support i++ or i-- (increment/decrement operators)?" for more information why.
You can fix your code like this:
require 'csv'
i = 0
CSV.foreach("survdata.csv", headers: true) do |row|
puts row
i = i+1
if i > 1 then
break
end
end
More information on the error message (thanks sawa):
Ruby does actually support i++
syntax. If it is followed by x
, it is interpreted as unary operator +
applied to x
, whose result passed as an argument to i+
. In your example, if i > 1 then; break; end
does not return any value, hence the error message "void value expression".