With a simple for loop I can trigger a potential infinite loop exception in the p5.js web editor
function setup() {
var cnt = 0;
var startTime = new Date().getTime();
for (i = 0; i < 80000; i++) {
console.log(cnt++);
}
var endTime = new Date().getTime();
console.log("done in " + (endTime - startTime) + " milliseconds");
}
Gives me output:
Exiting potential infinite loop at line 5. To disable loop protection: add "// noprotect" to your code done in 501 milliseconds
Which is not surprising as I see that the threshold has been increased to 500ms in p5.js-web-editor issues 174
What is surprising, at least to me, is that if I remove any of the semicolons the potential infinite loop is not detected after 500ms and my loop completes.
For example:
function setup() {
var cnt = 0 // no semicolon here..
var startTime = new Date().getTime();
for (i = 0; i < 80000; i++) {
console.log(cnt++);
}
var endTime = new Date().getTime();
console.log("done in " + (endTime - startTime) + " milliseconds");
}
Gives me output:
79999
done in 1737 milliseconds
My question is, why does removing a semicolon break the p5.js web editor's infinite loop detection?