For loop is not working in crystal get an error

For loops are a thing, but only in the macro context: Macros - Crystal. The primary reason for the difference is macros are somewhat special in that they need access to the program itself for code generation reasons.

Related: Is there a reason why loops using the « for » keyword are not implemented in Crystal?

P.S. Could also do like:

1.upto 10 do |i|
  puts i
end
1 Like