The currentQuestionIndex incrementor


Quick question about the instance variable currentQuestionIndex in QuizViewController’s implementation file. There’s a piece of code that compares the value in the incrementor to the number of pointers in the questions array:


// Step to the next question


// Am I past the last question?

if (currentQuestionIndex == [questions count]) {


    // Go back to the first question

    currentQuestionIndex = 0;


I just want to be clear on what exactly is happening here. Am I correct in assuming the following?

currentQuestionIndex++ is equivalent to currentQuestionIndex = currentQuestionIndex + 1

and since currentQuestionIndex is declared as an integer, it is automatically set to 0 when the app launches and increments by 1 each time the user hits the “Show Question” button until it equals the number of questions in the questions array.


Yes, ++ is the same as adding one. Yes, because this is an instance variable, it is automatically set to 0 when the QuizViewController is instantiated.