How do I break out of a loop in Scala?
Posted
by TiansHUo
on Stack Overflow
See other posts from Stack Overflow
or by TiansHUo
Published on 2010-04-30T06:34:08Z
Indexed on
2010/04/30
6:37 UTC
Read the original article
Hit count: 298
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?
© Stack Overflow or respective owner