# Infinite Loop - Sum All Numbers in Range

I have passed this exercise and a working solution is shown below so it is blurred.

I was playing with the input numbers and was seeing how high it could go and ran into the error message (this will happen when one of the inputs is >1200000):

Potential infinite loop detected on line 5. Tests may fail if this is not changed.

I don’t see how there would be an infinite loop here. Is this just a case of it taking too long to process so it gives that error?

Thank you for the help!

``````  **Your code so far**
``````
``````
function sumAll(arr) {
let sumArr = 0;
let min=Math.min(...arr);
let max=Math.max(...arr);
for (let i=min; i<=max; i++) {
sumArr = sumArr + i;
}
console.log(sumArr);
return sumArr;
}
sumAll([1,1100000]);

``````
``````  **Your browser information:**
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36`

Challenge: Sum All Numbers in a Range

Link to the challenge:

Exactly this. There is actually a formula to find the sum much, much faster that will avoid this warning.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.