I saw Liu Daocheng, a self-taught IT network, talking about the iterations. how can I see it? the main reason is that there are too many nonsense videos there. The logic thinking is broken!
Who can tell me what iteration is? What is the difference between iteration and recursion?
Be sure to use the code to speak. The theory alone does not understand it!
Reply to discussion (solution)
Function iteration ($ n) {$ s = 0; for ($ I = 1; $ I <= $ n; $ I ++) $ s + = $ I; return $ s;} function recursion ($ n) {if ($ n> 1) return $ n + recursion ($ n-1); else return 1 ;}echo iteration (10 ); echo recursion (10);/* iteration: use the original value of the variable to calculate a new value of the variable. if recursion is self-called, iteration is A non-stop call B. there must be iterations in recursion, but not necessarily in iteration. most of them can be converted to each other. use iterations instead of recursion */
Function iteration ($ n) {$ s = 0; for ($ I = 1; $ I <= $ n; $ I ++) $ s + = $ I; return $ s;} function recursion ($ n) {if ($ n> 1) return $ n + recursion ($ n-1); else return 1 ;}echo iteration (10 ); echo recursion (10);/* iteration: use the original value of the variable to calculate a new value of the variable. if recursion is self-called, iteration is A non-stop call B. there must be iterations in recursion, but not necessarily in iteration. most of them can be converted to each other. use iterations instead of recursion */
Is accumulation an iteration?
Use the original value of the variable to calculate a new value of the variable.
Should it be difficult to narrow down the concept of geography to accumulate? Although accumulation is also one of them
Iteration is to update to another value based on the original value segment.
Recursion is a space for leeching, calling layer by layer, and returning layer by layer
Iteration is to update to another value based on the original value segment.
Recursion is a space for leeching, calling layer by layer, and returning layer by layer
This metaphor is quite simple!