+ 1
What's the best way to understand nested loops !?!?
I'm just trying to bang my head with it but no hope of understanding it !?!
4 ответов
+ 2
So for those of you having trouble in understanding give this video a try !!
Link :
https://youtu.be/H7frvcAHXps
+ 2
Just look up to the sky! :)
Because whole universe is all about nested loops: the sun is performing a loop around the Milky-way, while the earth is performing another loop around the sun, while the moon is performing another one around the earth. I bet the Milky-way may be in another galaxy's loop. The list goes on..
Take them as all 'for loops' for instance. Video contents about space and planet intervals would be much helpful.
+ 1
For 2D loops it might help if you think the loops as tables.
This loop:
for (int i = 0: i < 10; i++) {
for (int j = 0; j < 5; j++) {
}
}
Could be thought like this:
0 1 2 ... 4 j
0 0&0 0&1 0&2 0&4
1 1&0 1&1 1&2 1&4
2 2&0 2&1 2&2 2&4
...
9 9&0 9&1 9&2 9&4
i
This might also help if you are supposed to print triangles and other polygons, but if you are using more nested loops this might not help