iNTERFACEWARE Products Manual > Learning Center > Learning Python > Conditional Statements and Loops > The for Statement |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
The for statement provides a convenient way to create a loop that does not run the risk of executing forever. Here is an example that uses for to display the numbers from 1 to 10:
Here, range(1,11) represents every number between 1 and 10. When used in a for statement, it tells Python to execute the loop once for every number in the range, assigning the number to x as it does so. In this example, when the loop is executed for the first time, x has the value 1. The second time through, x has the value 2, and so on. As a general rule, range(a,b) includes all integers from a to b - 1. It does not include b.
|