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 5943143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:21:10+00:00 2026-05-22T16:21:10+00:00

Good evening. I’m having trouble finding a condition that would stop a loop inside

  • 0

Good evening. I’m having trouble finding a condition that would stop a loop inside my program. I will try and explain it as generally as possible so the question might help others in the same situation:

I have a collection of objects.
With a piece of code inside the loop, I generate more objects.
I want to add these objects to the collection.
Once they’re added I’d like to iterate over them UNLESS they’ve been iterated over before.

Pseudo-code:

While (!everyObjectHasBeenIteratedOver){
    for (Object o : SetOfObjects){
        // Generate an unknown number of objects
        // Add those objects to the SetOfObjects unless they're already there
    }
}

So that’s basically it.
The only answer I know is by using Lists, which support the addition of elements over the iterating list without breaking up, however I, personally, am using HashSets.

Any ideas?

Thanks in advanced.

EDIT: Ended up using a set for the visited objects and another one for the not visited.
Condition: while (!notVisited.isEmpty()) {...}

  • 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-22T16:21:11+00:00Added an answer on May 22, 2026 at 4:21 pm

    I propose to use 2 collections: visited and toBeVisited. Visited may be Set and toBeVisited – Queue. So you add new items to queue only if they not visited yet. And when you add item to Queue, you also add it to Set.

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

Sidebar

Related Questions

Good evening, I'm having trouble with model binding and validation but I don't know
Good evening, In my app that I'm currently developing, I have a class that
Good evening all, I've been working on an MD5 tool in C# that takes
Good evening everyone. I am puzzling over the oddity that the jQuery Marquee plugin
Good evening, I am working on a program where some application config info is
Good evening, I am developing a set of Java classes so that a container
Good evening I have a JTable that I built with a TableModel how to
Good afternoon, does anyone know of a library that would allow me to read
Good Evening All, A client has asked that I develop a web application as
Good evening all, I'm trying to write a method that creates and returns a

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.