Search code examples
javacircular-list

Circular Tally Counter Not Rolling Over


I was practicing my java and was trying to make a simple counter with rollover at max, but for some reason it isn't rolling over. Any advice?

if(count++ < max){
    click();
 }

Solution

  • Be careful with count++. It evaluates to the current value of the count, then increments afterward. So if count is 3, and max is 3, count++ > max will return false, and then increment count. It looks like you want ++count, which increments, and then evaluates.