How round-robin algorithm can be implemented that runs in a loop for ever?
for (int i = 0; ;i++){
roundRobinIndex = i % numberOfWorkers;
}
The problems with the way above is that integer overflow
problem. It can also be implemented with checking the value of i
:
for (int i = 0; ;i++){
roundRobinIndex = i % numberOfWorkers;
if i == maxNumber{
i = 0;
}
}
But this way seems ugly. Maybe there is more elegant way?