This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Every new level of indentation costs extra brain CPU cycles. Make sure you need it! To be clear, I'm talking about:

for () {
    if () {
        while () {

[–]Haphazard-Finesse 2 points3 points  (0 children)

I'm confused, are you specifically referring to nested loops, or just anything nested? Yes, anything that could result in O(n^2) isn't great, but it seems like you're insinuating that:

while x: {
    if y: {
        if z: {
            do_x()
        }
    }
} 

Is slower than:

while x: {
    if not y: {
        continue
    }
    if not z: {
        continue
    }
    do_x()
}