I have a method, where i am comparing arraylist values inside the for loop.
I do not want to execute the Loop 2(see below code) if any single condition is true for loop1.
Now what happing is, for some values loop 1 is statisfy and for some other values loop 2 satisfy.So beacuse of this i am db is populating with wrong data.
I want to modify my code in such a way that. if any of the array list values are stisfying the loop 1 then compiler should return from return ERROR. It should not execte the code after that.
Loop checking condition is if(quant>Integer.parseInt(book.getQuantity()))
Action.java.
public String execute()
{
if(id.length == quantity.length)
{
for (int i = 0; i < id.length; ++i)
{
book = dao.listbookdetailsByBId(id[i]);
Double dq=new Double(quantity[i]);
int quant=dq.intValue();
if(quant>Integer.parseInt(book.getQuantity()))
{
//Loop 1 , this is executing if any of the quant is greater then book.getQuantity()..
//i want to stop executing LOOP2 ,if any of the value of quant is greater then book.getQuantity().
addActionError("You have entered an invalid quantity for the Book Title- ''"+book.getBookTitile()+"''.");
return ERROR;
}
/* Loop2 starts here
* Loop 2 , this is executing if any of the quant is lesser ..
* The below code should execute only if compiler does not reach to the loop1 */
// Some DAO code goes here
}
}
return SUCCESS;
}
Just use a break statement