0

I have a series of IF statements in order of execution, my dilemma is if one of the IF statements is entered I would like the calling method to wait till the called function is finished. The thing is my called function is recursive so I have no idea when it's going to end. Here's the calling method's code.

                if(log.isChecked())
                {
                    runlog(sdPath.getAbsolutePath());
                }
                if(tmp.isChecked())
                {
                    runtmp(sdPath.getAbsolutePath());
                }
                if(txt.isChecked())
                {
                    runtxt(sdPath.getAbsolutePath());
                }
                if(bf.isChecked())
                {
                    runbf(sdPath.getAbsolutePath());
                }
                if(ed.isChecked())
                {
                    runed(sdPath.getAbsolutePath());
                }

If log.isChecked() is entered, I would like the calling function(the code I've shown here, that function) to wait till it checks the next condition which is tmp.isChecked()

As I mentioned before ALL the called functions runlog, runtmp, runtxt, runbf, runed are recursive. How do I achieve what I want?

4

2 回答 2

2

我认为电影“盗梦空​​间”最好地解释了递归。你有 3 件事要做。

  1. 去睡觉。
  2. 梦。
  3. 起床吃一碗麦片。

想象你在做梦,然后在那个梦里有一个梦。你现在不能醒来吃饭,直到你退出更深的梦境并完成当前的梦境。

这基本上就是你的例子中发生的事情,除了你没有做梦你跑了第一个 if 并且你不能退出它,直到它达到它的返回条件然后你才能醒来并吃东西(进入第二个 if)。

于 2012-12-13T18:18:28.223 回答
1

这应该默认发生。递归的嵌套函数在这里没有区别。

每个 if 块只会在前一个块完成后执行,除非您的嵌套函数正在启动线程或类似的东西。

于 2012-12-13T18:01:42.380 回答