您可以将代码更改为 while() 循环,如下所示:(我分别将 i, j 替换为 m, n)
int m = 3, n = 3;
while( m++ == n-- ){ //Initially m and n are 3
//m becomes 4 due to ++
//n becomes 2 due to --
m = m + n; //m becomes 6
while( m % n != 0){ // 6 % 2 is 0
m = m + n; // Not called
}
m = m + 2; // m becomes 8
n = n - 2; // n becomes 0
//Goes back to the while(m++ == n--) to check condition again.
//However ( 8++ == 0--) is false, so while loop is not called again.
//but, the values of m and n change to 9 and -1 respectively.
}
混合各种类型的循环可能会使调试变得有点复杂。