I just made an utterly silly logical error in this code. What is it? (This is not a performance question, this code is simply wrong.)

I just made an utterly silly logical error in this code. What is it? (This is not a performance question, this code is simply wrong.)
