I have a while loop in a programming language. I am looking for an elegant way to subtract an intial value by one until the new value reachs zero, until zero the substrations return always zero.
I am using module operation but I have some problem to get the right solution For example:
// R project language
s = 5
for(i in 1:10) {
s = s - ((s) %% (s-1))
print(s)
}
[1] 4
[1] 3
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
[1] 2
what I wish is:
[1] 4
[1] 3
[1] 2
[1] 1
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0