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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:15:54+00:00 2026-05-12T05:15:54+00:00

I have a list of rows from a dataset that I need to iterate

  • 0

I have a list of rows from a dataset that I need to iterate through.

The problem is that the processing in the iteration may delete one or more rows from the list.

Since the list is being modified, I can’t use a foreach() loop.

But since it is possible some of the deletions may occur at elements BEFORE the one I’m processing, I also can’t use a for() loop (i.e, if I’m processing element , and that results in the deletion of element and also other elements , I can’t think of a way to adjust i to correctly point to the element following the one that I was processing).

How would you tackle this problem? My current thought it is to always process the first element in the list. If it gets deleted, process the new first element. If it doesn’t get deleted, the move it to an “alreadyProcessed” list, and process the new first element.

Is there an easier way?

  • 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-12T05:15:54+00:00Added an answer on May 12, 2026 at 5:15 am

    When modifying a list I’m iterating through, I always find it easiest to build a new list with the items I want to keep, and then use the new list to do whatever it was I was going to do.

    It really depends on what you’re doing with the data when you’re done, I suppose.

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

Sidebar

Related Questions

i have list of rows that user select and i want to delete them,
I need to delete about 2 million rows from my PG database. I have
I have an adjacency list of objects (rows loaded from SQL database with the
I have to read 100.000 rows from database, I use this code : List<elementClass>
I have a list view with many rows and have it set so that
I have one mysql query, which gets rows to designs list. In this list
I have a large file, with 1.8 million rows of data, that I need
I have a dataset that includes a list of species, their counts, and the
i have a list 1 column and 100 rows each with a number the
I have a list view contains 100+ rows. every time the user opens the

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.