# Thread: The modulo operator

1. Member
Join Date
Oct 2009
Location
Denmark
Posts
10
Rep Power
0

## The modulo operator

So I'm trying to understand the modulo operator and the use of it in a clock example.

The line:

Java Code:
```public void increment()
{
value = (value + 1) % limit
}```
Where value is defined a an integer is, if, I understand it correctly, meant to increment the "value" value with 1, untill reaching a preset limit at which the value will be set to 0, due to the fact that at this point there will be nothing remaing. i.e 24 % 24 = 0

However I thought when the result of the fraction were below zero as in for example 13 % 24 the remaing should be 13... which to me would screw the logic up in the given piece of code.

Well it doesn't and I therefore I must have misunderstood something.

Can anyone help me out there?

Thanks a lot
Martin

2. ## Re: The modulo operator

What's the remainder of 13 / 24? ... it's 13. So the logic holds.

3. Member
Join Date
Oct 2009
Location
Denmark
Posts
10
Rep Power
0

## Re: The modulo operator

Oh my god.... yes of course. I simply misread the code.

Thank you for pointing that out.

Cheers

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•