Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Strange behavior with nested loops

ANSWERED

 

I need to iterate through some elements, I'm generating the element id using a couple of loops.

for(let x=0;x<=3;x++){
  for(let y=0; y<=30; y++) {
    console.log(`${x} ${y}`);
  }
}

this seems pretty straight forward, but I notice toward the end I don't see all the output in console.

[11:13:46]2 26
[11:13:46]2 27
[11:13:46]2 28
[11:13:46]2 30
[11:13:46]3 2
[11:13:46]3 5
[11:13:46]3 9
[11:13:46]3 12

that's a snippet, and you can see '2 29' is missing, so is '3 1', and others.

What's causing this?

 
Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I think the debug bridge (or something) silently drops log lines when it gets saturated. This seems to happen at around 30 lines if written in quick succession. You could perhaps test this theory by slowing down the loop, or by printing intermittent lines.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
3 REPLIES 3

I think the debug bridge (or something) silently drops log lines when it gets saturated. This seems to happen at around 30 lines if written in quick succession. You could perhaps test this theory by slowing down the loop, or by printing intermittent lines.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Yes, if I pick specific example, or use modulus, all the iterations are there.

Thank you!

Best Answer

👍

So your code was fine all along. 🙂

Peter McLennan
Gondwana Software
Best Answer
0 Votes