It's me (again)...

This is a discussion on It's me (again)... within the C# Programming forums, part of the General Programming Boards category; Yet another problem... This one is a while loop, but I know this should work, as less than 10 lines ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    129

    It's me (again)...

    Yet another problem... This one is a while loop, but I know this should work, as less than 10 lines down, there is another while loop along exactly the same principle, and that works...

    Code:
    wjh = rnd2.Next(0,11);
    systemOwn[maplocation[random,random2,0]] = empireCode[wjh];
    exists2 = SystemOwner.Contains(systemOwn[maplocation[random,random2,0]]);
    while(exists2 == true)
    {
           wjh = rnd3.Next(0,11);
           systemOwn[maplocation[random,random2,0]] = empireCode[wjh];
           exists2 = SystemOwner.Contains(systemOwn[maplocation[random,random2,0]]);
    }
    SystemOwner.Push(systemOwn[maplocation[random,random2,0]]);
    As you can see, we are generating a random number to be used in the empireCode string type, and then assigning what is stored in there to systemOwn[val]. The maplocation[random,random2,0] array is a number between 100 and 599. Then the obvious while loop. Which looks good... Like the code I spoke of earlier -

    Code:
    maplocation[random,random2,efg] = rnd3.Next(100,599);
    exists = mapLocCount.Contains(maplocation[random,random2,efg]);
    while(exists == true)
    {
        maplocation[random,random2,efg] = rnd4.Next(100,599);
        exists = mapLocCount.Contains(maplocation[random,random2,efg]);
    }
    mapLocCount.Push(maplocation[random,random2,efg]);
    Virtually exactly the same thing, the only difference being the names of the variables I am using. So why doesn't the first one continue through the first one when it encounters an instance already contained inside the stack? Closest I have come to solving this is, it doesn't like a random function inside the brackets on the empireCode variable.

    Help!

    Btw, no nitpicking my general coding style. workingUglyCode = good; brokenSexyCode = Bad;
    Last edited by DanFraser; 02-04-2005 at 06:51 PM.
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21