• 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
Marshal
Posts: 53182
124
  • 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.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!