Java:for循环忽略条件

时间:2016-02-25 22:25:01

标签: java android

我的for循环忽略了!found字段,即使在找到== true:

时仍然继续
public int getDownYEntities() {
    int loc = 16;
    boolean found = false;
    EntityType eCheck;
    for (int col = locY; col < 17 || !found; col++) {
        eCheck = level[locX][col];
        System.out.println("Called");
        if ((eCheck == EntityType.ROCK) || (eCheck == EntityType.BOULDER) || (eCheck == EntityType.KEY) || (eCheck == EntityType.EXIT)) {
            switch (eCheck) {
                case ROCK:
                    loc = col - 2;
                    found = true;
                    break;
                case BOULDER:
                    loc = col - 2;
                    found = true;
                    System.out.println("Test1");
                    System.out.println(found);
                    break;
                case KEY:
                    loc = col - 2;
                    found = true;
                    break;
                case EXIT:
                    loc = col - 1;
                    found = true;
                    break;
            }
        }
        else
        {
            loc = col-1;
        }
    }
    return loc;
}

日志:

 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Test1
 I/System.out: true
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called
 I/System.out: Called

我是一个完全白痴还是什么?

1 个答案:

答案 0 :(得分:6)

col < 17 && !found

你想&#34;和&#34;,不是&#34;或&#34;。