在for循环中使用"i ++"

use*_*221 1 java for-loop

嗨,我有一个问题,我可以使用这样的代码:

        if (low != mid && mid != high) {
        for (int i = 0; i <= mid; i++) {
            boolean bool = Determinate.isPointLeftSide(a, auxiliaryListTwo.get(i), auxiliaryListTwo.get(i + 1));
            if (bool == false) {
                p = auxiliaryListTwo.get(i);

            } else {
                boolean bool1 = Determinate.isPointRightSide(a, auxiliaryListTwo.get(i + 1), auxiliaryListTwo.get(i));
                boolean bool2 = Determinate.isPointRightSide(a, auxiliaryListTwo.get(i + 1), b);
                if (bool1 == true && bool2 == true) {
                    p = auxiliaryList.get(i + 1);
                }
                else{
                    i++;
                }
            }

        }

    }
Run Code Online (Sandbox Code Playgroud)

我在else部分使用了"i ++",这是正确的吗?

Vla*_*nov 7

基本规则是你不要i在循环内以任何方式改变计数器变量(这里).如果要跳过当前迭代,则应使用continue;statement.