我继续在我的 for 循环中使用嵌套 if 进行无限循环

I keep on getting a infinite loop in my for loop with nested if

这是我的 while 循环,大循环然后我们有一个带有嵌套 if 的 for 循环,问题是 if 中的代码继续循环并使程序崩溃。当我 运行 我的代码并添加一个现有的 ID 号来验证它时,它会不断发送它存在的错误消息,我无法把手放在循环的问题所在

while (exist>=0){
    exist=0;
    for(int i=0; i<idArr.length; i++){
        if(AddID.getText().equals(idArr[i])){
            exist=1;
            JOptionPane.showMessageDialog(null, "ID already exists!", "Clinic System", JOptionPane.ERROR_MESSAGE);
            AddID.setText("");               
            addName.setText("");
            DOBADD.setText("");
            Address.setText("");                              
            PhoneNum.setText("");
            GenderAdd.setText("");
            break;                                
        }                            
    }
    if(exist==0) {
        try{    
        myconn = DriverManager.getConnection(url, user, password);
        //mystatShop = myconShop.createStatement();
        //myresShop = mystatShop.executeQuery("INSERT INTO patient_test VALUES (?, ?)");
        String SQL= "INSERT INTO PATIENT_INFO  VALUES (?,?,?,?,?,?)";
        PreparedStatement pstate = myconn.prepareStatement(SQL);
        pstate.setString(1,AddID.getText());
        pstate.setString(2, addName.getText());
        pstate.setString(3, DOBADD.getText());
        pstate.setString(4, Address.getText());                             
        pstate.setString(5, PhoneNum.getText());
        pstate.setString(6, GenderAdd.getText());

        pstate.executeUpdate();
        JOptionPane.showMessageDialog(null,"Insertion Successful");
        AddID.setText("");               
        addName.setText("");
        DOBADD.setText("");
        Address.setText("");
        GenderAdd.setText("");
        PhoneNum.setText("");

        myconn.close();
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
        break;
    }
}

while 参数表示 while (exist>=0)
所以根据代码存在的值总是等于或大于 0。所以循环永远不会结束。
像这样放
while (exist>0)
我也没有看到使用嵌套循环的理由。您可以仅使用 for 循环遍历数组。