A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
could someone help me with the concept behind iteration in python
anonymous
 5 years ago
could someone help me with the concept behind iteration in python

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Iteration 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 #end 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0So basically iterative is using the while sumthing sumthing: do this and recursive is for each of these: do this ? Or have I misunderstood?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0No wait, the recursive one modifies what we are working on right? So for problem set three it would change the target string...

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0thank you both for the help

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0No 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:

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok well the wikipedia info looks good and rwmuller did a great job
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.