0

run function in thread class PROBLEM: I want control back to the outerloop when butn value is equal to "c" i used break statement to get control back to label outerloop but it's not working even though the butn is equal to c the control is not coming to outerloop and it is not printing "waiting for socket to connected"

public void run() {
    try {
        outerloop:
        while (true) {
            System.out.println("waiting for socket to connected");
            sock2 = ss2.accept();
            System.out.println("socket connected from download");
            dis2 = new DataInputStream(sock2.getInputStream());
            dos2 = new DataOutputStream(sock2.getOutputStream());

        for(;;){
            System.out.println("control is waiting @ line 291");
            try{
                butn = dis2.readUTF();
            System.out.println("the butn pressed" + butn);
            if (butn.equals("b")) {
                browse();
            }
            if (butn.equals("c")) {
                sock2.close();
                dis2.close();
                dos2.close();
                jump  outerloop;
            }
            if (butn.equals("g"))
             {
                getfile1();
               }
            }catch(Exception x){
            x.printStackTrace();
                    }   
               }//for loop

        }//while loop
    } catch (Exception x) {
        x.printStackTrace();
    }

}//run

  public void browse(){}
public void getfile1(){}

}
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
  • 1
    http://stackoverflow.com/questions/462373/difference-between-break-and-continue-statement – guido May 03 '15 at 09:52
  • What happens when you run the debugger with a break point on this if (butn.equals("c")) { line? – saml May 03 '15 at 09:57
  • Have a look at the link posted by @ᴳᵁᴵᴰᴼ. It explains it well how you can leave the loop and continue with your `while` loop. Seems you misunderstood the usage of a [labeled break](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html) – SubOptimal May 03 '15 at 10:04
  • sorry jump is not working at the place of jump now i used `break outerloop ` then it just prints **waiting for socket to connected socket connected from download system is waiting @291 the butn pressed c – Chaitanya Wodeyar May 03 '15 at 10:06
  • s now i used `continue outerloop ` in the place of jump outerloop now it is working :) thanks everyone – Chaitanya Wodeyar May 03 '15 at 10:31

0 Answers0