How do I break out of a loop in Scala?
- by TiansHUo
For Problem 4 of Project Euler
How do I break out a loop?
var largest=0
for(i<-999 to 1 by -1) {
for (j<-i to 1 by -1) {
val product=i*j
if (largest>product)
// I want to break out here
else if(product.toString=product.toString.reverse)
largest=largest max product
}
}
And does anyone know how to turn nested for loops into tail recursion?