ButthethingaboutRykerShinisthatitworks a lotlikenormallooseandthatyouhavesomekindofexitconditionsthatjumpsyououtoftherecursivesothatthefunctionstopscallingitselfoverandoveragain.
Sowhat I'm gonnadointhisvideoiswe'regonnatake a lookatit, a fewexamplesofnormalnonrecursivefunctions, andwe'regoingtochangethemtoberecursivefunctionso I canshowyouthedifferencebetweenthetwo.
Andwecanalsovisualizewhat's goingontostartwith.
We'regonnacoverthemostbasicexample, whichis a functionthatcountsdownfromthespecifiednumber.
Yougiveitallthewaydowntozero.
Solet's justtake a lookatthisbasicfunction.
Allwehaveis a simplefourloopthatcountsdownfrommynumber.
Aslongaswe'regreaterthanzero, it's goingtoattracttwentiestimetogothrough a loop, andit's justgoingtoprintoutthatnumber.
It's somucheasiertodoitin a loop, anditjustmakesmoresenseeasiertowrapyourheadaround.
Solet's lookatit.
Anotherexampleof a recursivefunction, onewhereweactuallyaretakinganinputandconstantlygrowingourinputinsideof a recursivefunction, whichissomethingthat's verycommoninmostrecursivefunctions.
Sohere's anotherexampleof a verycommentiterativeapproachthatwewouldtaketo a solutiontosomeofrangeofnumbers.