Question: I want to count from 0 to n. And when I have reached n, adding 1 to n would give me 0 again.

For example:

0, 1, 2, 3, 4, 0, 1, 2, ...

Is there such an algorithm to do this?

Edit:

I need an equation to simple get the number after the given number. In the example above if I put 1 in the equation I would get 2, if I put 4, I would get 0. Maybe algorithm isn't the best word for this problem.

Answer: 
This will be the remainder when the consecutive whole numbers are divided by $n+1$.

A C++ code, if that please you:

> 
> for(i=0;%@%@;i++)
> 
> 
> {
> 
> 
> k=i%(n+1);
> 
> 
> cout<< k;
> 
> 
> }
> 
> 
> 

In the above code, Substitute your value of $n$. And, in between the place where there is a wild card entry, you could put in the maximum number upto which you'd like to count.
Maple counting code :

```
n:=4:

for a from 0  do
s:=0:

for k from 1 to n do
s:=s+1:
print(s);
end do;

end do;

```

Output is sequence : $0,1,2,3,4,0,1,2,3,4,0,1....$