What does “foo = (foo + 1) % bar” exactly do?
From the Finch audio library:
- (void) play
{
[[sounds objectAtIndex:current] play];
current = (current + 1) % [sounds count]; // this line here...
}
I try to grok it: There is a number of sounds n, and current
is increased by 1 on every iteration. As soon as current
is bigger th开发者_如何学JAVAan number of sounds n, the modulo returns zero. That way, it starts from the beginning.
Is this correct?
Yes, that's right.
精彩评论