How to better understand logic of multiple nested loops...

How to better understand logic of multiple nested loops? After 3rd or 4th nest in Python all my logic turns in utter shit. It just doesn't work as it supposed to work. Do you have the same problem with nested loops and if statements in Python?

Attached: images (3).png (220x220, 2K)

what does this have to do with python?

for loops make this type of problems, I never had problems with nested for loops in C.

If you regularly end up with over 2 nested loops, you're doing it wrong.
Decompose the reasoning in separate functions if you really need.

why do you even need to nest for loops 4 times ?

The problem isn't python, its your code structure.

Any code with 4 nested loops is going to look like shit and you're not going to know whats going on properly. Refactor

>4 nested loops
Do not

Attached: [HorribleSubs] Anima Yell! - 04 [720p]_00:07:38_10.jpg (1280x720, 113K)

what if i'm iterating over a hypercube?

What are matrixes

You can have multiple nested loops for vector arithmetic for example but in numpy you have special iterators for multidimensional arrays

Look at numpy reference for iterators or better try to make your operation broadscatable if possible

Speaking of nested loops: one of my friends once told me he had to start creating double character variable names for his loop indexes because he had so many nested loops he ran out of a-z.

>mfw

Attached: 1390942128920.jpg (395x387, 31K)

Kek I'm in the same boat. I struggled to do 2 nested loops in python, ended up writing my loops like I would C loops.

AHAHA
>he had at least 26 loops
>he uses single letter variables
Absolutely based. He's on a whole other level of thinking.

the python snakes look like two npcs sideways

Were all the loops really in the same scope, or is he just an idiot?

Are you sure you did the indentation correct?

>Were all the loops really in the same scope
Yes
>is he just an idiot
Yes

>for loops considered harmful
do the smart thing and use goto instead

>4th nest
visualize motherfucker

Attached: 9millionhoursinpaint.png (730x244, 5K)

more than two nested loops is insane

how horrible

Any more than 2 nested loops and things get way too computationally intensive in terms of pure algorithmic intensity. A good programmer will avoid the nesting of loops for any reasons and this is one of them.

> k < 7
i applaud your effort

What in the fuck was it supposed to do?

4th nested loop? NO NO NO NO

before doing something, always ask if you should be doing it at all.

multiple nested loops are awful. find another solution. Try using different data structures to mediate between loops.

what's map()?
what's list comprehansion?
what are generators?
what are lambdas?

You shoud avoid loops and especially nested ones. they just take to much time. at best in your case by O(n^4)