Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a cirular index

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
Hello,
i am trying to implement an circle using an index. I have an index of 0 to 7. i want to increase the index 3 places at a time but when it gets to 7 and want it to wrap round to 0 and so on. for example if the index is on 6 then after increment then the index will be on 1. any ideas on how i can do this?
thanks for your help





 
You need to increment first then modulus 8. i.e.

x = (x + 3) % 8;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top