2015-12-10 66 views
-1

我怎麼能放棄這個while循環,聲明決裂也沒用〜我怎麼能退出while循環netbean

while(rs.next()) { 

    String uname=rs.getString("User_ID"); 
    String password=rs.getString("User_PW"); 
    String cusType=rs.getString("CUS_TYPE"); 
    if ((user.equals(uname)) && (pwd.equals(password))){ 
     if (cusType.equals("1")){ 
     Account_Info_IND accountInfo = new Account_Info_IND(); 
     accountInfo.setVisible(true); 
     this.dispose(); 
     **BREAK;** 
     } 
     else { 
      Account_Info_COMP accountInfo1 = new Account_Info_COMP(); 
      accountInfo1.setVisible(true); 
      this.dispose(); 
     } 
    } 


} 
+0

你的意思是:*陳述突破是無用*? – sstan

+2

可能的原因'break'是沒用這裏,它不獲取調用。事實上,更好的解決方案將是建立一個更好的查詢 – MadProgrammer

+0

我想退出while while循環時它滿足if語句的條件,所以我把一個「break」放在if語句中,但是系統說錯誤〜 – cyrus

回答

3

我不明白爲什麼你認爲break語句是沒用的,你有沒有正確地解釋了它出了什麼問題。但使用break語句退出循環的非常有效的方式。

作爲示例,運行下面的代碼片斷地看到,它工作得很好:

public static void main(String[] args) { 
    for (int i = 0; i < 10; i++) { 
     System.out.println(i); 
     if (i == 2) { 
      break; 
     } 
    } 
} 

輸出:

也許通過看着上面的代碼,你將能夠弄清楚你出了什麼問題r代碼。

對於它的價值,我完全MadProgrammer的評論認爲,通過編寫接受必要的參數正確的查詢,你可能甚至不需要有你的循環內的條件。