Decrementing for loop with cached variable