1
2
By default, if you just give range() a number, it starts at
0 and goes by 1s until it reaches the number you
provided. Zero is a valid iteration, but if you don’t want
it, you can start at 1. Consider this example:
>>> for x in range(1,3):
... print(x)
...
1
2
To change the increment from the default of 1, you can
add a third attribute to the range() statement. In the
following example, you start at 1 and increment by 3
until you reach 10:
>>> for x in range(1,11,3):
... print(x)
...
1
4
7
10
Remember that these ranges are up to and not including
the final number you specify. If you want to go all the
way to 10 in this example, you need to set your range to
11.
While Loops
Whereas the for loop counts through data, the while
loop is a conditional loop, and the evaluation of the
condition (as in if statements) being true is what
determines how many times the loop executes. This