I am trying to access all even elements and odd elements in the same for loop like so:
This code is obviously wrong because doing an i+1 while trying to access odd elements, increases the value of i which leads to wrong result by the time I try to access the next even element. I understand that my code is wrong but I was just trying to show what is it that I am seeking to do. Could someone tell me what is the right way to do this?
Instead of using i++ to increment the index by one, you just need to increment it by two. Make sense? I'll let you figure out the little bit of code yourself, but just replacing that i++ is going to do it.