I have a simple program written in C++. It generates random numbers, and stop when the sum of those numbers equal or greater than 100. The code looks like:
vector<int> container; while(container.sum() <100) { int new_number = rand()%10 + 1 ;// generate a number in range 1 to 10 container.push_back(new_number); // add new number to the container } What is the best way to handle the task in Scala? (without using while loop?)
It seems that FoldLeft or FoldRight function doesn't have ability to break at a condition?