Best way to learn loops in python & make it stick?
Nested for loops - bad practice? How to avoid?
Performance-wise, nesting loops increases execution time exponentially. You should look at unrolling loops and precalculating values that won't change during each iteration.
Otherwise, they are sometimes necessary.
More on reddit.comAvoiding Nested Loops?
If you really need to iterate over them, you need to iterate over them.
The general guidance of triple nested loops is to avoid spaghetti code which is hard to follow. If your inner and second loops are functions, this can improve code clarity:
for (auto layer : layers) {
process_layer(layer);}
and then
void process_layer(layer_t layer) {
for ( x ) { for ( y ) { do_something } }
} More on reddit.com Ideas for practicing for and while loops?
For: print out only even numbers between 1 and 100. Now do it without using an if statement.
While: Ask the user for a secret password. Keep going until they get it right. Now do the same without using an if statement.
These are probably the most basic ideas. Once you have them down, you can build on your knowledge.
More on reddit.com