Content: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Background: Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Notes Sharp Wood Rockface Leather Honey Vertical Triangles
Welcome to Xbox Chaos: Modding Evolved

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
Mc Jayce

C#
C# Nested Loops (Wtf!?)

2 posts in this topic

So my c# teacher had to take a week off pinch.gif (to India, lolz), and as a result a random substitute teacher was given the task to teach a-bunch of beginners the Nested Loop. Which sucks and makes no sense!

Can anyone explain this to me in "simple person speak"?

*I know how loops work (for... while...) but this seems like LOOP-CEPTION

i.e.

for (blaablaa)

for (blaablaa)

-Good luck, and as always thank you!

Share this post


Link to post
Share on other sites

Well this is a little late, but I'm answering anyway. The concept of having one loop in another is not that hard to understand.

For example, let's say we had 2 for loops (like you have), and we go like this:


for(int i = 0; i < 5; i++)
for(int x = 0; x < 5; x++)
Console.WriteLine("i: " + i.toString() + " | x: " + x.toString());

That would result in the output of:


i: 0 | x: 0
i: 0 | x: 1
i: 0 | x: 2
i: 0 | x: 3
i: 0 | x: 4
i: 1 | x: 0
i: 1 | x: 1
...

I don't see what you are having trouble with when looking at this. All you have to do is make sure that your variables in the for loop are different for every nested for loop, otherwise things will get screwed up. If you are still having trouble on this, mind elaborating on what is so confusing?

Edited by Hetelek

Share this post


Link to post
Share on other sites
Sign in to follow this  
Followers 0