Site menu

CodeCook.io

  • Languages
    • C
    • C++
    • CSS
    • Git
    • HTML
    • Java
    • JavaScript
    • jQuery
    • PHP
    • Python
    • Ruby
    • Scala
  • basic
  • for
  • loop

Scala - For each loop

Loop over all elements in list.

Code that executes each itteration
0
841
  • Share on Facebook
  • Share on Google+
  • Share on Twitter

Iterate list and side effect

{{list}}.foreach { item =>
  {{body}}
}
java

Notes

last update: June 16, 2015

0
826
  • Share on Facebook
  • Share on Google+
  • Share on Twitter

Using an iterator

{{list}}.iterator.foreach { item =>
  {{body}}
}
java

Notes

last update: June 16, 2015

0
866
  • Share on Facebook
  • Share on Google+
  • Share on Twitter

Using list comprehension

for (item <- {{list}}) {
  {{body}}
}
java

Notes

last update: June 16, 2015

Advertisement

This project is hosted on DigitalOcean, try it and support us

Related concept

  • Counter loop
  • Single comment
  • Break out of loop
  • Function default parameter
  • Loop while condition is true
  • Do loop while a condition is true

Other language

  • Python
  • JavaScript
  • jQuery
  • AngularJS
  • PHP
  • Javascript ES6

Random task

  • Git commit changes
  • Strip whitespace around string
  • Linear gradient
  • Show docker container standard output continiously
  • Create and resolve promise
  • Blog
  • About
  • License