Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

can someone please clarify the difference between iterative and recursive?

OpenStudy (anonymous):

Iterative functions usually work by way of a 'for' or 'while' loop to do identical processing bit by bit while recursive functions do just one bit but call other instances of themselves to do the rest. Look at the examples below to combine a list of strings. Notice how the recursive function picks out the first string in the list and combines it with "rest" which is determined by creating another instance of recursive() which works on the list starting at the next string in the list. Each pass cuts the list down by 1 until there is only 1 string left, the last one which is returned. list = ['These ', 'words ', 'are ', 'combined'] def Iterative(list): combo = '' for i in range(len(list)): combo = combo + list[i] return combo def recursive(list): if len(list) ==1: return list[0] word = list[0] rest = recursive(list[1:]) combo = word + rest return combo Hope that helps!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!