while(rs.next())
  {
  String x = rs.getString(1);
  String y = rs.getString(2);
  if(x.equals(qinshi) && y.equals(password))
  {
  XianShi xianshi = new XianShi();
  this.dispose();
  }
  else
  {
  System.out.println("11111");
  text1.setText("");
  text2.setText("");
  text3.setText("寝室号或密码错误,请重新输入!");
  }
  }怎么样让if条件满足的时候执行
                                                        XianShi xianshi = new XianShi();
  this.dispose();
之后退出while循环语句呢?

解决方案 »

  1.   

    在上两条语句之后加
    break;
    就行 吧
      

  2.   

    貌似break只能够退出if语句,而其后的else还是会继续执行,不能够跳出while循环。return倒是可以退出while循环了,但是整个程序也结束了。这个······不是本意哈!
      

  3.   

    break结束循环。直接在break点,跳出循环,与if...else...无关。
    验证如下: int i = 10;
    while (true) {
    while (true) {
    if (i > 5) {
    System.out.println("inner level: in If, break");
    break;
    } else {
    System.out.println("inner level: in Else"); }
    }
    if (i > 5) {
    System.out.println("in If, break");
    break;
    } else {
    System.out.println("in Else"); }
    }
    输入结果:
    inner level: in If, break
    in If, break另外,类似的还有,continue终止本次循环 
    注意break只能跳出一层循环,当为多层循环时表示跳回上一层循环。而return和exit则是无论有多少重循环跳出最外层循环外。 
      

  4.   


    给你的while循环加个标志,比如loop: 然后break loop;
      

  5.   

    // breakpoint: 加上
    //
    // while(rs.next())
    //    {
    //        String x = rs.getString(1);
    //        String y = rs.getString(2);
    //        if(x.equals(qinshi) && y.equals(password))
    //        {
    //            XianShi xianshi = new XianShi();
    //            this.dispose();
    // return breakpoint; 加上
    //        }
    //        else
    //        {
    //            System.out.println("11111");
    //            text1.setText("");
    //            text2.setText("");
    //            text3.setText("寝室号或密码错误,请重新输入!");
    //        }
    //    }这样应该能解决 你试试
      

  6.   

    if(x.equals(qinshi) && y.equals(password))是不是这里的问题?
    应该是if(x.equals(”qinshi“) && y.equals(”password“))加个双引号试试?
    break应该可以跳出循环。
      

  7.   

    你可以把while(rs.next())中的变量用一个Boolean型的变量b=true代替,当if满足时让b=false。
      

  8.   

           if(x.equals("qinshi") && y.equals("password"))
                             {
                                 XianShi xianshi = new XianShi();
                                 this.dispose();
                                 break;
                             }
      

  9.   

    label:
       while(true)
        {
                 while(true)
               {
                //return ;
                // break lable;
                }
        }
      

  10.   

    System.exit();也可以代替this.dispose()
      

  11.   

    break是跳出循环的,怎么可能执行了if之后继续执行else呢,唯一可能的原因就是根本就是你那个if判断语句false了
      

  12.   

    break是跳出循环的,if判断语句false了
      

  13.   


    break 是跳出整个循环体的
      

  14.   


    int a = 0;
    while(rs.next()) { String x = rs.getString(1); String y = rs.getString(2); if(x.equals(qinshi) && y.equals(password)) { XianShi xianshi = new XianShi(); a++; break; } else { System.out.println("11111"); text1.setText(""); text2.setText(""); text3.setText("寝室号或密码错误,请重新输入!"); } }if(a != 0){
     this.dispose();}
      

  15.   


    这个方法不错。
    break是跳出循环,return是跳出方法了。
      

  16.   

    楼主。if else 明显只能二者进一不可能又进if又进else的
    在if体内加break是正确的操作。