This is probably a basic scala question but not able to figure out how:
How can this java loop be expressed using Scala for:
for (int i=1;i<100000;i=2*i)
I understand this is one possible way:
def loopByTwiceBefore(from:Int, to:Int)(f:Int=>Unit):Unit = {
if (from<to){
f(from)
loopByTwiceBefore(from*2, to)(f);
}
}
But is there a more canonical way to do this in Scala.
You can use the
iteratefunction fromIterator(or from other classes likeStream,Listetc.):