int n=0; int max = 100; //通常的做法(省略上下文) if(n>=max) { n = 0; } n++; //巧妙的做法 n%=max n++ 转载于:https://my.oschina.net/mlgb/blog/296082