Round robbin

I was doing some simple load balancing tests on an application I'm building.  I wanted to load multiple queues from different places in my code using a simple round-robin approach.  A very simple thing to do, and this is what I came up with:


int index = 0, max = 10;


index += index >= max ? (index * -1) : 1; will increment the index counter until it reaches the limit (10), then start back at zero again. I don't know why I find that line so beautiful, but I just do.  I like it when you can do stuff in a single line of code.