Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recursive: See recursive
Message
 
To
04/01/2006 20:34:03
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01083365
Message ID:
01083418
Views:
10
>Einar,
>Where is the recursion (or recurring is the correct spelling) in this code? Maybe you meant just to stop there. I think foreach() became quickly popular but while() sounds to be more appropriate to me. break is another option.
>Cetin

I wish UT could compile my code here. The example I gave was totally messed up and would not compile. Well that is what I get for writing code directly into the message.

Recursion is spelled correctly but the original post did not show any recursion. The example below now has recursion. The method CallRecursive calls the method RecursiveMethod and RecursiveMethod calls itself and then RecursiveMethod calls itself ...... and so on and so forth.
private void RecursiveMethod(TreeNode treeNode)
{
   if (foo == bar)
   {
     MessageBox.Show(treeNode.Text); // I don't want to continue my recursive search!!
   }

   foreach (TreeNode tn in treeNode.Nodes)
   {
      RecursiveMethod(tn);
   }
}

private void CallRecursive(TreeView treeView)
{
   foreach (TreeNode n in treeView.Nodes)
   {
      RecursiveMethod(n);
   }
}
Well my question still stands: what is the best way of breaking out of a recursive loop?

Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform