+ 1
Who can help me out,i don't seem to understand the concept loops
Python for beginners
2 ответов
+ 2
Thanks
+ 1
When there is a repetitive task to be done, that is where computers improve man's productivity. The more we can use computers to loop a set of instructions that otherwise we would have to do manually, the more valuable is that program to us.
Some loops are designed to loop forever. You can use a goto statement for this.
Others must NOT loop forever becuase it prevents the rest of the program from executing. Of those there are three basic ways to control how many times a loop executes.
1) Loop for as long as a changeable condition is true. Or similarly, Loop while waiting until a changeable condition occurs. Use a "while" loop for both these kinds.
2) Loop only a given number of times. Use a while loop with a counting variable, or use a for loop with the range() iterable.
3) Loop to iterate through a list or other iterable data. Use the various forms of a for loop for this.
I hope this improves your basic understanding. Go back and review the lessons. Run the 'Tap to try' examples and experiment.