What is the difference between iteration and recursion?

后端 未结 8 798
太阳男子
太阳男子 2021-01-30 11:52

What is the difference between iteration and recursion and why/when is one better:

while (true) {
    // Iterating
}

8条回答
  •  梦谈多话
    2021-01-30 12:23

    Recursion and iteration are different ways to think about a solution. It would be dificult to explain in depth the difference in full scope. In your sample code, you aleady showed the difference. Recursive function is the one that calls itself, while iterative is the one that loops through some block of code. Here are some articles to help you understand them better: Recursion wiki

    Iteration wiki

    CodeProject SO #1

    SO #2

提交回复
热议问题