"foo =(foo + 1)%bar"到底是做什么的?

don*_*ile 1 objective-c

来自Finch音频库:

- (void) play
{
    [[sounds objectAtIndex:current] play];
    current = (current + 1) % [sounds count]; // this line here...
}
Run Code Online (Sandbox Code Playgroud)

我试着理解它:有许多声音n,并且current每次迭代都会增加1.一旦current大于声音数n,则模数返回零.这样,它从头开始.

它是否正确?

Noa*_*oon 8

恩,那就对了.