-1

So, I am running a for Loop from within a while-Loop. And if my if() finds something(from within the for-loop), it should stop both the for and while-loop. Btw, this is Java. Here my Code:

while(!(objecFound)){
            for(int i = 0; i <= currObsTile.length; i++){
                if(currObsTile[i].tile == endTile){
                    //If this is true, it needs to stop the while loop
                }
            }
        }

Thanks

1 Answers1

-1

You can solve this with a Java label:

    OuterLoop:
    while(!(objecFound)){
        for(int i = 0; i <= currObsTile.length; i++){
            if(currObsTile[i].tile == endTile){
                //If this is true, it needs to stop the while loop
                break OuterLoop;
            }
        }
    }
Ring
  • 2,249
  • 5
  • 27
  • 40