Ad
  • Default User Avatar

    So the for loop starts at the highest index in the List (size-1) and as long as the index is bigger than -1 (until it reaches 0, since that's still a valid index) it will perform the if statement, and remove any even number in the List without skipping anything. The problem with the initial code was that when you reach an even number while incrementing a for loop, it removed that number and caused all the subsequent numbers to shift their index down one place. This caused the bug of skipping over some even numbers. So you could either make sure you decrement i when you remove an even number if you use a normal increasing for loop, or you could start at the end and make your way down, since removing an even number won't affect the index of the previous terms. I hope this helps! :)