开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜