My notes are a little hairy. If you can understand them, just read them.
Write a method to achieve the loop effect without the if statement: int I = 0;
// 1-6 cycles. Int fun (INT max) {static int I = 0; I = I % Max; I ++; return I;} int main () {fun (6 );}
// Traditional statement: 1-6 cycles. Int fun (INT max) {static int I = 0; if (I> MAX) I = 0; I ++; return I ;}
Modulo Application
// The specified number of changes within a period of time. The change cycle is the same. Int n_time = 3; for (float time = 0; time <1; time ++ = 0.02) {// segment float slice = 1.0f/n_time; // 0-slice 3 times. Float M = fmodf (time, slice); If (M> slice/2) {printf ("% F \ n", m );} else {printf ("-% F \ n", m);} // |__ _ __|}// features: // The result obtained by time % slice is never greater than that obtained by slice. It will only loop in the cycle of 0-slice. // slice/2, change count 1 * cycle count 3 // slice/3, and change twice each time, it will change 6 times. // Slice/N, and the number of changes: (1/slice) * (n-1)