I am having a bit of difficulty trying to effectively kill two birds with one loop. I have cropped the below code to focus on my trouble area. I'm trying to combine what would be two different loops into one. Theoretically, it makes sense that I should be able to do this. However, being new to all of this, I'm essentially clueless. I've had this functioning as two different loops. Each of those reflected in the comments of the code itself.
My primary error comes in the form of an 'undeclared identifier'[j] highlighted in the screen-grab below. I have parsed the walk-through and numerous online forums for something relative, but remain scratching my head as I believe that it is declared in the for loop above it. Any assistance with this would be greatly appreciated. I'm sure that this is silly.