What make this part of code

I don’t understand what this part of the code does
currentIndex = (currentIndex + 1) % questionBank.size

nextButton.setOnClickListener {
currentIndex = (currentIndex + 1) % questionBank.size
updateQuestion()
}

That expression on the right side of the assignment operator yields a value which is always greater than or equal to 0 and less than the value of questionBank.size.

Thus the value of the currentIndex can always be used to safely index the associated array questionBank.

This is commonly used to wrap around the value of an index variable.

2 Likes