|
-
January 23rd, 2011, 01:39 AM
#1
Can't figure out how to structure my loops
Hello,
I'm trying to write a program which requires nesting an undetermined number of loops. I am completely confused by how I can do this without hard coding the actual loops. To say the entire purpose of the program is pretty long and complicated, so I will give a simple example of what I am trying to do:
Let's say I have a class called box. This class contains a string "description" as well as some other attributes. I load a file which fills a random number of List<boxes> When I'm done, I have n List<boxes> loaded. Now let's say one of the boxes in the lists has a description containing "key". Another box, probably but not necessarily in a different list, contains a description with "lock". I need to iterate through every pair of boxes to compare each one and see which gets a key-lock combination.
If I knew that there were, for example, 3 List<box>, I would just code 3 nested for loops and iterate that way. However, I have absolutely no idea how to structure the code where the number of lists is a variable. The only way I can think of is to have a program which codes another .cs file containing the required number of loops, linking to visual studio, and executing it, but that seems way too complicated. Is there another way to do this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|