Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8907325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:53:13+00:00 2026-06-15T02:53:13+00:00

I have a method, where i am comparing arraylist values inside the for loop.

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:53:14+00:00Added an answer on June 15, 2026 at 2:53 am

    Just use a break statement

    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()+"''."); 
              break; 
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is the method I have. It works fine for comparing Strings. I would
I'm wondering if my method below of comparing an array of strings (or any
I am using this code for comparing string values in a method, which work
Is it possible to execute a String as method? Let's say I have a
I have a method which runs incredibly slow testing in device (iPhone3G) comparing to
I have a method which comparing data in two dataTable. After comparing I´d like
I am comparing arrays of objects and I have a method that determines whether
I have an implemented of Pearson's Similarity score for comparing two dictionaries of values.
I have following method which is failing . I think I am comparing double
I have method that returns Drawable , and if its Bitmap object is recycled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.