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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:19:39+00:00 2026-05-25T01:19:39+00:00

List<string> Getlist() { List<string> mylist; for (bool successFlag = false; !successFlag; ) //It will

  • 0
List<string> Getlist()
{
    List<string> mylist;
    for (bool successFlag = false; !successFlag; )  //It will definitely enter the loop once.
    {
        successFlag = true;
        mylist = new List<string>();
        for (int i = 0; i < n; i++)
        {
            var CDF = GetCDF(); // IEnumerable, each call of GetCDF() gives different result
            if (!CDF.Any())
            {
                fail++;
                successFlag = false;
                break;
            }
            string item = GetNext(CDF);
            mylist.Add(item);
        }
    }
    return mylist; // Here IDE poses an error
}

I guess there is a way to recursively use Getlist() instead of do a for loop and flag retry, maybe some kind of immutable method?

i dont wanna initiate the list outside the loop because i would like to discard the list when successFlag is false;

Discard simply means when successFlag = false, then mylist.removeall. And then start everything over again as fresh, so I am asking for an approach to recursively call GetList() instead of clear the states in the method

Update

do while works!

  • 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-25T01:19:40+00:00Added an answer on May 25, 2026 at 1:19 am

    The issue has to do with this line. If it doesn’t run you List would never be initialized.

    for (bool successFlag = true; !successFlag; )
    

    Now if you change your code to this it should work fine.

        List<string> Getlist()
        {
            List<string> mylist= new List<string>();
            for (bool successFlag = true; !successFlag; )
            {
                for (int i = 0; i < n; i++)
                {
                    var CDF = GetCDF(); // IEnumerable
                    if (!CDF.Any())
                    {
                        fail++;
                        successFlag = false;
                        break;
                    }
                    string item = GetNext(CDF);
                    mylist.Add(item);
                }
            }
            return mylist;
        }
    

    Update :

    Run untill GetCDF(); is not empty. This can cause an infinite loop if GetCDF() is always empty!!!

    List<string> Getlist()
    {
        List<string> mylist= new List<string>();
        for (int i = 0; i < n; i++)
        {
            var CDF = GetCDF(); // IEnumerable
            if (!CDF.Any())
            {
                            Thread.Sleep(1000); //Sleep for 1 second.   
                fail++;
                return Getlist();
            }
            string item = GetNext(CDF);
            mylist.Add(item);
        }
    
        return mylist;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a condition like this List<String> mainList = new ArrayList<String>(); for(int i=0; i<3;
I have the following code: // Form the continuities list string[] continuities = new
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
I have the following bean method signatures: public String foo(); public List<String> getList(String bar);
I have a list string tag. I am trying to initialize a dictionary with
How to populate List (string) items on console window in c++cli.
Here's the code I have: var commandsBuffer = List[String]() commandsBuffer ::= cmd.exe commandsBuffer ::=
I'm attempting to do a simple bubble sort code to get familiar with list/string
I have a list of string values that I want add to a hashtable
I have a String List with items like this Root Root/Item1 Root/Item2 Root/Item3/SubItem1 Root/Item3/SubItem2

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.