0

So I have a while loop with a if function in it. When the if function gets called I want to exit both the if and the while loop and continue down my code.. Yet break does not let me do this? What should I do.

As can see in my code i put break INNER; in the end of my if function and then INNER: outside the while loop, hoping it would jump here but i get a error even.

while(rob.getPixelColor(594,718).getBlue()!=34){
   System.out.println("3 start queue");
   rob.delay(500);
   if((rob.getPixelColor(754,428).getBlue()>40) && (rob.getPixelColor(754,428).getRed()<30)){ 
      System.out.println("4 start queue");

      rob.delay(500);
      System.out.println("scanning for popup");

      rob.mouseMove(750,408);
      rob.delay(400);
      rob.mousePress(InputEvent.BUTTON1_DOWN_MASK);
      rob.delay(400);
      rob.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK);
      rob.delay(400);
      break INNER;
   }                                
} INNER:
Jens
  • 67,715
  • 15
  • 98
  • 113

2 Answers2

2
INNER: while (...) {
     break  INNER;
     ...
}

The label must label the looping statement.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • It seems like when I get to the "INNER" part of the code I jump to "break INNER;" and not the other way around which was my intent. How do I do this? Changing position on the two does not work for whatever reason.. – user2957672 Jun 08 '14 at 22:11
  • In this case a label was not even needed; a `break` would jump out of the first enclosing loop (while/for/do). – Joop Eggen Jun 08 '14 at 23:30
0

use and boolean variable instead of a break Statement:

boolean exit = true;
while(rob.getPixelColor(594,718).getBlue()!=34 && exit){
   System.out.println("3 start queue");
   rob.delay(500);
   if((rob.getPixelColor(754,428).getBlue()>40) && (rob.getPixelColor(754,428).getRed()<30)){ 
      System.out.println("4 start queue");

      rob.delay(500);
      System.out.println("scanning for popup");

      rob.mouseMove(750,408);
      rob.delay(400);
      rob.mousePress(InputEvent.BUTTON1_DOWN_MASK);
      rob.delay(400);
      rob.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK);
      rob.delay(400);
      exit = false;
   }                                
} 

If you are in the if statement set the boolean variable to false and you leaf the while Loop because the condition is false.

Jens
  • 67,715
  • 15
  • 98
  • 113