Issue
Is there any way I could ensure an int
doesn't cross a certain limit? and if it needs to (if the program is adding numbers to the int
and it crosses the limit) it goes back to 0 and does the job from there?
Solution
It sounds like you want the modulo operator %
.
If the upper limit is limit
then
value = value % limit; // Or value %= limit
will "reset" the value
back to zero if it's about to pass the limit.
Answered By - Some programmer dude Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.