>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.