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 wOOdy-Soft 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
 
Use the modulus operator to reset the index to 0 once it gets to 8. This should cycle your index from 0 to 7.

index = ( ( index++ ) % 8 ) ;
 
Someone else also asked this in another forum

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

Part and Inventory Search

Sponsor

Back
Top