I need to set an int variable in each iteration +-1, the range should be between 0-10. When i add 1 to 10 -> 0 when i add -1 to 0 -> 10. I know i need to go with modulo here but cannot find any solution.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This seems to easy, but if you really want to use modulo, did you try;
or for “ultimate readability” and probably still better performance just
Please note that the requirements locks y down to being -1 or 1.