Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
foreach (HtmlAgilityPack.HtmlNode table in doc.DocumentNode.SelectNodes("//div[@class='top_b']"))
            {
            Outer:
                foreach (HtmlNode b in table.SelectNodes("b"))
                {
                    MessageBox.Show(b.InnerText.ToString());

                    foreach (HtmlNode p in table.SelectNodes("p"))
                    {
                        MessageBox.Show(p.InnerText.ToString());
                    
                        foreach (HtmlAgilityPack.HtmlNode class_table in table.SelectNodes("//table[@class='t']"))
                        {
                         
                             MessageBox.Show(class_table.InnerText.ToString());
                        
                           goto Outer;
                        }
                    }
                }
            }

When it comes to goto outer then it resets the foreach. That is, the counter value is not saved.

ps/ Excuse for my english
Posted
Updated 21-Dec-11 6:11am
v3
Comments
CPallini 21-Dec-11 6:34am    
What counter? If you meant 'b' than that's natural. What do you want to do?
[no name] 21-Dec-11 6:56am    
I meant that the value foreach reset. That is first he worked with the first element
foreach (HtmlNode b in table.SelectNodes("b"))
In the next cycle, it should work with the next element

1 solution

There is no counter.

Why the heck are you nesting those loops anyway?
They all run on the same table data, so nesting them just means that the same information is shown lots of times.

You are a beginner, so:

REMOVE THE GOTO FROM YOUR CODE

Now, forget that goto exists at all for at least three years.
Then you will have enough experience to work out when you should actually use it. Which is very, very infrequently. So far, I have never used a goto in any of my C# code!

Now work out what you are actually trying to do on paper, and implement that.
 
Share this answer
 
Comments
LanFanNinja 21-Dec-11 13:01pm    
+5"Now, forget that goto exists at all for at least three years."
I would change this to say
Now, forget that goto exists at all for EVER and EVER and EVER !! :)
OriginalGriff 21-Dec-11 14:07pm    
No, goto does have a place: as a "bail out of all these loops" it can save a lot of time consuming spaghetti when you can't refactor the code into a separate method. But I do wish they wouldn't teach it as a part of the beginners syllabus...
LanFanNinja 21-Dec-11 17:04pm    
True.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900