How to loop counter?

Hi all,

I’m currently getting an issue when trying to loop a counter (firefly component) as there is inevitably recursive data streams.

All I’m trying to do is create a loop - once the counter reaches the end it either reverses or starts at the beginning of the same list again, over and over, continuously. Does anyone know how to create a looped counter? Or, how to cycle through items in a list at specific time periods in a continuous loop?

Any suggestions would be much appreciated.


Counter (11.2 KB)

% = Modulus helps…

0%3 = 0
1%3 = 1
2%3 = 2
3%3 = 0
4%3 = 1
5%3 = 2

Thanks for your reply but I’m not sure what you mean? How would this be applied?


Looking at the image of your code, I am confused… The content of the first panel on the left isn’t used, only the list length? No reason to flatten the output of Lng, and you can avoid the A-B component and its slider by using an expression on the Lng output (“x-1”). A very common pattern:

expression (8.0 KB)


Hi, you are right, the information contained in the panel is not used in this example as I would use the output of the counter to go back and select items from the original list - should I get it to work. At present I can’t see how to reset the counter once it reaches a certain list item in that list though

Any thoughts would be much appreciated.

Ah that’s ideal! Not in a million years would I have thought of that.

Exactly what I was after!

Many thanks.

I understand exactly what you mean @TomTom - this is elementary programming that goes WAY BACK, long before GH - but it must be mentioned that with Wrap List Item = true (the default), you get the same result without Modulus. I know you know that too, just saying…

This forum is a mix of issues that are very specific to GH, such as data trees and geometry, and issues like this (Modulus) that are fundamental to elementary programming in any language, from the earliest days.

1 Like

not to forget bitshifting

There’s also a counter in Generation which does what you need

1 Like (9.1 KB)