edit: An example since it wasn't clear yet: userInputs = {0,0,0,0,0} nextNumberIndex = 0
userInputs = {0,0,0,0,0}
nextNumberIndex = 0
The user inputs: 10 userInputs = {10, 0, 0, 0, 0} nextNumberIndex = 1
userInputs = {10, 0, 0, 0, 0}
nextNumberIndex = 1
output is 10
The user inputs: 12 userInputs = {10, 12, 0, 0, 0} nextNumberIndex = 2
userInputs = {10, 12, 0, 0, 0}
nextNumberIndex = 2
output is 10, 12
The user inputs: 10 userInputs = {10, 12, 0, 0, 0} nextNumberIndex = 2 notice
userInputs = {10, 12, 0, 0, 0}
nextNumberIndex = 2
output is 10, 12 again
notice how this input is completely ignored here, because it's a duplicate.
The user inputs: 99 userInputs = {10, 12, 99, 0, 0} nextNumberIndex = 3
userInputs = {10, 12, 99, 0, 0}
nextNumberIndex = 3
output is 10, 12, 99
The user inputs: 10 userInputs = {10, 12, 99, 0, 0} nextNumberIndex = 3
userInputs = {10, 12, 99, 0, 0}
nextNumberIndex = 3
output is 10, 12, 99 again
Then toTo print our result we use
This will result in the numbers 10, 12, 99 (at the end) and stop because the next i is equal to nextNumberIndex so the for loop ends. These are exactly the non-duplicat numbers that we wanted.