Is recursion a feature in and of itself?

后端 未结 9 509
陌清茗
陌清茗 2021-01-30 05:49

...or is it just a practice?

I\'m asking this because of an argument with my professor: I lost credit for calling a function recursively on the basis that we did not cov

9条回答
  •  终归单人心
    2021-01-30 06:47

    From what I can deduce from your question, using a recursive function to ask for input in case of input failure is not a good practice. Why?

    Because every recursive functions call gets pushed on to the stack. Since this recursion is driven by user input it is possible to have an infinite recursive function and thus resulting in a StackOverflow :-p

    Having a non recursive loop to do this is the way to go.

提交回复
热议问题