Next Button & Array Index


#1

I am on Page 41-42. So after creating the listener for the NEXT button I run the program I notice if I keep clicking the NEXT button it continually loops thru the question array. This is not what I was expecting to happen. Once I get to the last question I was expecting to get a OUT OF INDEX error when I clicked it again. Can someone explain why it starts back over at the beginning even though I never reset mCurrentIndex to 0 and I keep adding one to it?

Does it have something to do with the % on the following line…I am not sure what that is doing.

mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;


#2

[quote=“derrellgore”]Does it have something to do with the % on the following line…I am not sure what that is doing.

mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;[/quote]

Yes, it does.

% in Java is the remainder operator.

(3 + 1) % 4 = 0