I was wondering the correct way to format a situation such as this, where I have a def, a foreach and an if clause all nested, requiring braces. Currently I find it hard to read, and there is no obvious place to put the 'x =>' bit. Thank you.    def getAnswer(): String ={  var sum = 0  (0 until 1000).foreach   { x =>     if (x % 3 == 0 || x % 5 == 0)    {      sum += x    }  }  sum.toString}
Preferred Scala code style for several embedded brace sets
coding style;scala
Scala has an official style guide which recommends putting opening braces on the same line, not on a line of their own. Parameters should also be on the first line.def getAnswer(): String = {  var sum = 0  (0 until 1000).foreach { x =>     if (x % 3 == 0 || x % 5 == 0) {      sum += x    }  }  sum.toString}In your specific case, you should probably remove most of your braces, as all but the outermost are not needed (also, filter would be idiomatic here):def getAnswer(): String = {  var sum = 0  0 until 1000 filter (x => x % 3 == 0 || x % 5 == 0) foreach (x => sum += x)  sum.toString}