CSC300 / CSC402
:
Converting a while loop to a recursive function
[6/14]
Create a helper function.
Determine the helper function's parameters.
Add one parameter to the helper function's
signature
for each local variable we need for our loop.
Write the body of the helper function:
Change
while
loop to an
if
block.
Instead of incrementing the index variable, do a
recursive call
to the helper function, passing the incremented value of the index variable.
Call the helper function
passing the initial values of the variables.