could someone help me with the concept behind iteration in python
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Iteration is the process of performing an action until a certain test is met. For example if you are driving to Grandma's house and she lives at exit 10 then you evaluate each exit to see if it is exit 10 if it not then you continue driving and test the next exit.
Here is a quick example using a "while" statement. The interation occurs as I increase the exit until it equals 10
#Are we there yet/
exit = 5 #set starting exit
while exit <> 10: #test for exit 10, while exit DOES NOT EQUAL 10
print "Only at exit ", exit, " keep on going"
exit = exit +1 #drive to the next exit.
#run test again
#when test is true
print "We are at exit ", exit, "I hope Grandma is home"
#This prints when we get to exit 10
You can copy this program, save it and run it to see what it outputs./ The ouput should look like this:
Only at exit 5 keep on going
Only at exit 6 keep on going
Only at exit 7 keep on going
Only at exit 8 keep on going
Only at exit 9 keep on going
We are at exit 10 I hope Grandma is home
So basically iterative is using the
while sumthing sumthing:
and recursive is
for each of these:
? Or have I misunderstood?
No wait, the recursive one modifies what we are working on right? So for problem set three it would change the target string...
Not the answer you are looking for? Search for more explanations.
thank you both for the help
No no no - I'm not helpful. I'm just trying to understand it too.
After I posted this I found and read the Wikipedia entry on recursion: http://en.wikipedia.org/wiki/Recursion_%28computer_science%29
It helped me heaps, especially the bit about the Fibonacci function where it's written in both pseudocode and python.
So for iterative code you use for: or while: but for recursive you call the function within the function using things like if: elif: and else:
ok well the wikipedia info looks good and rwmuller did a great job