• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving Value from Array as [cnt % arrayvariable.length]

 
Kumar Navin
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recently I came across a way of retrieving values from an array as below:



The end result of output was the same in both the cases, with % and without %.
What is the advantage/disadvantage when we retrieve like " listofvalues[i % listofvalues.length]" from an array.

Regards,
-Kumar.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try changing the continuation condition to i < listofvalues.length * 2 and see what happens. You will have to comment out line 5.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic