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循环语句呢?
{
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循环语句呢?
break;
就行 吧
验证如下: 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则是无论有多少重循环跳出最外层循环外。
给你的while循环加个标志,比如loop: 然后break loop;
//
// 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("寝室号或密码错误,请重新输入!");
// }
// }这样应该能解决 你试试
应该是if(x.equals(”qinshi“) && y.equals(”password“))加个双引号试试?
break应该可以跳出循环。
{
XianShi xianshi = new XianShi();
this.dispose();
break;
}
while(true)
{
while(true)
{
//return ;
// break lable;
}
}
break 是跳出整个循环体的
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();}
这个方法不错。
break是跳出循环,return是跳出方法了。
在if体内加break是正确的操作。