0

I tried to break out of a for loop but it doesn't break.

How do I get or break out of this do...while loop from inside of the for loop?

Here CompanyEmployee is an ArrayList of objects of the Employee class and the CasualEmployee class inherits from the Employee class.

do {
     System.out.print("ENTER ID:\t");
     String s=s3.nextLine();

            for(int i=3;i<9;i++) {
                System.out.println(CompanyEmployee.get(i).getID());
                    if(s==CompanyEmployee.get(i).getID()) {
                        String data=CompanyEmployee.get(i).toString();
                        WeekSchedule[check1][check]=data;
                        break;                  
                    }
            }
}
while(true);
mustaccio
  • 18,234
  • 16
  • 48
  • 57
bijay
  • 1

1 Answers1

1

Use a label to indicate which loop you want to break out of:

    loopLabel: do{

      ...
      for(int i=3;i<9;i++){

        if(...){
          ...
          break loopLabel;
        }
      }
    }
    while(true);
maccaroo
  • 819
  • 2
  • 12
  • 22