Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Recursive: See recursive
Message
 
À
04/01/2006 20:34:03
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01083365
Message ID:
01083418
Vues:
11
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform