Foreach and counting in Scala
Was looking for the equivalent of Ruby's:
ruby
(1..5).each {|x| puts x }
or:
ruby
(1.upto(5)).each {|x| puts x}
in Scala, and found that:
scala
(1.to(10)).foreach { println }
results in the same output. Cool!
Written by Alexandra Mirtcheva
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Scala
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#