analogWrite not functioning in if statement

I...not really. I think I understand what you were saying about how it's basically resetting brightness every time it goes through the loop, but I don't understand how I'd go about fixing that.