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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:04:13+00:00 2026-05-12T06:04:13+00:00

hey, this i have a loop that adds gathered strings and ints into an

  • 0

hey, this i have a loop that adds gathered strings and ints into an object, and then adds that object into a list. I need it to check if there is already an object with a property == to the one i’m about to assign, and then depending on which the property is, I either want to change one of its properties, or still add a new object. I’ll be sorting this later. Here’s where I’m stuck. I have marked the line (currently commented out) which when activated, causes the command line to freeze. The weird thing is that i use the IDENTICAL code earlier with no trouble.

As you can see, I have some other code currently commented out, as this bit needs to work before I can continue, but I left it in to allow you to get more of an idea of what i am doing.

solved. i actually had to move it another two loops upwards. THANKS!

        //IF THIS IS THE FIRST ONE, ADD IT!
        var refSize = Referrals.Count();
        if (refSize == 0)
        {
        var NewReferral = new Referral(referringURL.Trim(), referringWords.Trim(), 3);
        Referrals.Add(NewReferral);
        }
        else
        {
        for (int i=0;i<refSize;i++)
        {

            // RESET BOOLS
            URLPresent = false;
            KeywordPresent = false;

            // IF THE URL IS ALREADY PRESENT
            //if (Referrals[i].URL == referringURL)
            //{
                //URLPresent = true;

                // CHECK IF THE KEYWORD IS ALREADY PRESENT
                //for (int ii=0;ii<Referrals[i].Keywords.Count;ii++)
                //{
                //  if (Referrals[i].Keywords[ii] == referringWords)
                //  {

                        // ADD TO OCCURRENCES
                //      Referrals[i].Occurrences++;
                //      KeywordPresent = true;
                //  }
                //}

                // ADD KEYWORD TO LIST
                // ###
                // ###
            //}

            // IF THE KEYWORD ISN'T THERE && THE URL ISNT THERE, ADD A NEW REFERRAL OBJECT
            if (URLPresent == false && KeywordPresent == false)
            {
                var NewReferral = new Referral(referringURL.Trim(), referringWords.Trim(), 3);
                //Referrals.Add(NewReferral);  //HERE IS MY PROBLEM! UNCOMMENTING THIS LINE CAUSES A FAIL.

                //URLPresent = true;
                //KeywordPresent = true;
            }

            // IF THE URL IS THERE, BUT THE KEYWORD ISNT, ADD AN ELEMENT TO THE REFERRAL.KEYWORDS LIST
            //else if (URLPresent == true && KeywordPresent == false)
            //{
                //Referrals[i].Keywords.Add(referringWords);

                //URLPresent = true;
                //KeywordPresent = 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-12T06:04:13+00:00Added an answer on May 12, 2026 at 6:04 am

    The specific problem is that you’re chasing your own tail. Every time you add a new element to the list, Refferals.Count goes up (your loop will never end if you keep adding elements). You should either pull the count out into a variable and use that into your loop or use something like Referrals.Contains …

    var refSize = Refferals.Count();
    
    for (int i=0;i < refSize; i++)
    {
     // same
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 144k
  • Answers 144k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Assume you have a class or some other container that… May 12, 2026 at 8:35 am
  • Editorial Team
    Editorial Team added an answer Hibernate works with standard JDBC data sources, so there is… May 12, 2026 at 8:35 am
  • Editorial Team
    Editorial Team added an answer Are you using SunJDK or OpenJDK? I think OpenJDK uses… May 12, 2026 at 8:35 am

Related Questions

I have a Perl script, that's supposed to match this string: Sometimes, he says
Hey I was just wondering if there is a cool one liner that would
Some time ago I asked a question about nested loops on SO and as
In an object-oriented programming style does how does one tend to handle graphics? Should
Hey peoples, I've been studying Java for a couple of weeks, and have decided

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.