 # understanding deep looping for

Hi all in a for loop there are three part initializer; condition; iterator

for(i=0; i<10; i++) {

console.log(i);
};

Output
0,1 2,3,4,5 and so on.

In a deep loop the inner loops works harder then the outer loop. So if you had a nested three loop. I would like to know when the third loop would finished it statment. heres is the code.

for(i=0; i<10; i++) {
for(j=0; i<10; j++) {
for(k=0; j<10; k++) {

}
}
}
print i;
So thge way I understand Deep looping is like a combination lock. Lets say the combination lock code is 123.

eg i=1, j=2 k=3,

to crack the code start a 0 and work your way up to 9. from the right most to the left. starts at
000,
001
002
003,
and so on. Now the third loop statment is no long true.
Next is the second loop.
001, 002.

What im trying to understand is how to use deep looping.

Thank you

``````void setup()
{
Serial.begin(115200);
Serial.println("Start ");

for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
{
for(int k=0; k<10; k++)
{
Serial.print(i);
Serial.print(j);
Serial.print(k);
Serial.println();
}
}
}

// simpler
for (int i=0; i<1000; i++)
{
if (i <100) Serial.print('0');
if (i <10) Serial.print('0');
Serial.println(i);
}
}

void loop()
{
}
``````

That is normally called "nested looping"

Say outer was from 0,1,2 middle was 4,5,6 and inner was 7,8,9

inner increments 3 times then middle increments and inner increments 3 times then middle twice more, finally outer increments and the above happenss again ...

Then the output seen would be 0 4 7 0 4 8 0 4 9 0 5 7 0 5 8 0 5 9 0 6 7 0 6 8 0 6 9

1 4 7 1 4 8 1 4 9 1 5 7 1 5 8 1 5 9 1 6 7 1 6 8 1 6 9

2 4 7 2 4 8 2 4 9 2 5 7 2 5 8 2 5 9 2 6 7 2 6 8 2 6 9

Understand?

Yes, but the example given was:

`````` for(i=0; i<10; i++) {
for(j=0; i<10; j++) {
for(k=0; j<10; k++) {

}
}
}
``````

This example will never end. k will keep incrementing and rolling over and continuing to increment. Forever.
… or at least until the power is removed.

Nice spot vaj4088!

Mark

Yes, didn't see the apparent cut & paste typo's there.