Skip to content

Files

Latest commit

 

History

History
33 lines (24 loc) · 795 Bytes

ForLoop.md

File metadata and controls

33 lines (24 loc) · 795 Bytes

Pattern: Missing use of parentheses in for loop

Issue: -

Description

For-comprehensions which lack a yield clause is actually a loop rather than a functional comprehension and it is usually more readable to string the generators together between parentheses rather than using the syntactically-confusing } { construct:

for (x <- board.rows; y <- board.files) {
  printf("(%d, %d)", x, y)
}

is preferred to

for {
  x <- board.rows
  y <- board.files
} {
  printf("(%d, %d)", x, y)
}

Example configuration

<check enabled="true" class="org.scalastyle.scalariform.ForLoopChecker" level="warning"/>

Further Reading