[BCLUG] About Array wrapping with modulus

Steve Litt slitt at troubleshooters.com
Sun Sep 3 15:09:42 EDT 2023


Hi all,

About Array wrapping with modulus.

Nice! Until now, I've usually used a linked list that wraps around,
which is waaaaay overkill compared to a modulus.

I think I have an idea for an improvement to the solution at
https://bclug.ca/counter-wrapping-with-modulus/ . My thought is that
hard coding the ID into each array element is redundant, with the
disadvantage that if you decide to add, delete or reorder, you need to
also change the IDs.

Instead, you could leave out the manually placed IDs, and follow the
array declaration with a loop that writes IDs matching the element's
position in the array. Now you can add, delete, and rearrange at will
without worrying about IDs.

If you want, you could also use that loop to write the background
colors from the 5 element background color array. I don't know if such
automated background color setting would yield any benefits or not.

Thanks for this. I just now very strongly recorded your array modulus
wrapping in my head, so I'll never again be tempted to use a linked
list, unless there's some other reason for using a linked list. 

SteveT

Steve Litt 

Autumn 2023 featured book: Rapid Learning for the 21st Century
http://www.troubleshooters.com/rl21


More information about the Discuss mailing list