Is there a reason why loops using the « for » keyword are not implemented in Crystal (as opposed to Ruby)?
After all, the « for … in …. » construct is present in most modern programming languages (Python, Go, JavaScript, Swift.etc.)
Is there a reason why loops using the « for » keyword are not implemented in Crystal (as opposed to Ruby)?
After all, the « for … in …. » construct is present in most modern programming languages (Python, Go, JavaScript, Swift.etc.)
Thanks!
I saw the following snippet on : Crystal for Rubyists · crystal-lang/crystal Wiki · GitHub
#for loops are not supported but you can add them via macro:
macro for(expr)
{{expr.args.first.args.first}}.each do |{{expr.name.id}}|
{{expr.args.first.block.body}}
end
end
for i in [1,2,3] do
puts i
end
It doesn’t seem to work.
It there a typo or is it just plain wrong?
It’s just outdated I’d say due to Let `case when` be non-exhaustive, introduce `case in` as exhaustive by asterite · Pull Request #9258 · crystal-lang/crystal · GitHub which made in
a keyword. See For macro.