У меня есть простой код, подобный следующему:
try {
int i = 0;
while (i < size) {
System.out.println("i is" + i);
if (someCondition) {
System.out.println("do sth");
someCondition = true;
i++;
System.out.println("i is" + i);
} else {
System.out.println("doAnotherThing");
someCondition = true;
i++;
System.out.println("i is" + i);
}
}
} catch(Exception){
}
Вывод этого фрагмента кода:
i is 0
do sth
i is 1
i is 0
doAnotherThing
i is 1
Должно быть больше I, чем разрыв цикла, но это не так,Есть ли у вас мнение по этому вопросу?Я работаю над этим вопросом с 5 часов, может быть, я что-то упустил.Я буду рад, если вы сможете мне помочь.
Заранее спасибо.
РЕДАКТИРОВАТЬ: я хотел упростить вещи, но, по-видимому, это не сработало :) ОК Вот настоящий код:
public void (Analyzer analyzer){
try {
int i=0;
while (i < analyzer.size()) {
System.out.println("i is" + i);
Object anInstance = analyzer.getObject().get(i);
if (anInstance.getDatabaseCreated()) { //this comes from another class and is //false in the first place
dropObject(analyzer.getId(),i); // removes object
createAnInstance(analyzer.getId(), i, anInstance.getTypes()); //creates another instance
anInstance.markCreated();
Query query = createInsertQuery(analyzer.getId(), i, anInstance.getTypes());
for (int j = 0; j < anInstance.rowCount(); j++) {
insertRow(query, anInstance.getTypes(), anInstance.getRow(j));
}
i++;
System.out.println("i is" + i);
} else {
createAnInstance(analyzer.getId(), i, anInstance.getTypes());
anInstance.markCreated();
Query query = createInsertQuery(analyzer.getId(), i, anInstance.getTypes());
for (int j = 0; j < anInstance.rowCount(); j++) {
insertRow(query, anInstance.getTypes(), anInstance.getRow(j));
}
i++;
System.out.println("i is" + i);
}
}
} catch (Exception ex) {
Logger.getLogger(AnalyzerService.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex);
}
}