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

  • SEARCH
  • Home
  • 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 7075429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:10:35+00:00 2026-05-28T06:10:35+00:00

I have a nested for loop. it works, kinda. It only reads the first

  • 0

I have a nested for loop. it works, kinda. It only reads the first if statement as true. It ignores all possible true statments after that.

for(int i = 0; i < inGroups.length; i++)
{
    for(int g = 0; g < theGroups.length; g++)
    {
        if( inGroups[i].equals(theGroups[g]) )
        {
            gLV.setItemChecked(g, true);
        }
    }
}
  • 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-05-28T06:10:35+00:00Added an answer on May 28, 2026 at 6:10 am

    Your code looks fine. As @Hot Licks mentioned, you should use a debugger and/or add print statements to see what’s going on.

    Couple of general comments about your code:

    • You should make sure that your Group object or whatever is in your arrays has implemented an equals method otherwise it will always be false.
    • Are you sure that setItemChecked can handle more than one value? If set is called twice does it just overwrite the previous value?
    • Your code is very inefficient (O(N^2)). You could consider doing something like the following which is O(N). It won’t matter if the arrays are small of course. If you use this method then you will need to implement hashCode() and equals() methods.

      Set<Group> inGroupsSet = new HashSet<Group>();
      // load inGroups into a set
      for (Group group : inGroups)
          inGroupsSet.add(group);
      // look up each Group in theGroups in the set
      for (int g = 0; g < theGroups.length; g++)
          if (inGroupsSet.contains(theGroups[g]))
              gLV.setItemChecked(g, true);
      

    Hope something here helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two nested loop in XSL like this, at this moment I use
If I have a for loop which is nested within another, how can I
What if I have nested loops, and I want to break out of all
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
as per the title; is it possible to have nested comments in valid HTML?
I have a very large nested for loop in which some multiplications and additions
I have a nested list, List<List<String>> intable; where I would like to sort all
I have this massive nested loop scenario that is calling the DB and making
I have a jQuery function that finds all the images nested in a container
I have a nested loop structure in my code. Sometimes, I get the below

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.