If I have a variable say x and set it to x=2 and then increment it, it happens in some systems that the variable after a number of increments reaches a max value and then resets back to its lowest value. Is there a general name for such a variable? Similar to "counting in a ring" or a modulo count for example

x++ //now x=2
x++ //now x=3
x++ //now x=4
x++ //now x=1

In mathematics, modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" upon reaching a certain value—the modulus (plural moduli).

From mathematics, Modular arithmetic a subfield of Ring theory.


This behaves like an integer overflow, but as suggested by Daniel Jour in his comment, “[overflow] implies that there's not enough space to store further values”, so this won't be the right term.

I may suggest CircularCounter, but I doubt it would be that clear for anyone. I won't use Modulo suggested in a comment: when I see a modulo, I expect a division, and I'm lost when I only see addition.

However, I'm not sure there is an exact name for that, simply because the case itself isn't that frequent.

You may have a better luck searching for a name in a context of the domain logic where you need such rule.

  • 1
    -1 for the "Overflow". This implies that there's not enough space to store further values (have a 5) and also suggests that the result is wrapped, which is not a mandatory consequence of an overflow (though very common). – Daniel Jour Dec 4 '16 at 13:57
  • @DanielJour: indeed, the suggested term is wrong for the reasons you gave. Thank you for your feedback; I edited my answer accordingly. – Arseni Mourzenko Dec 4 '16 at 14:36

I'd call it a Cycle.

Rails already has a view helper method called cycle that can essentially do this; you pass it a range or an array of values inside a loop and each successive value is called the next time you loop.

<% models.each do |model| %>
    <li class="<%= cycle('odd', 'even') %>"><%= model.name %>
<% end %>

The thesaurus adds a few more options:

  • sequence
  • series
  • round

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.