Question: ```
a = 0
b = 1
print a
print b
for i in range (102):
    c = a + b
    a = b
    b = c
    print c

print "The 103rd number is", c

```

I don't understand how the for statement works. I understand everything except how the program continues till the 103rd element and understands that it has to add the last two numbers to get the next number. I understand that a is equal to b and b is equal to c. 

Is it because after adding c, it changes the vales of a and b then goes back to the for statement? And that is where I am confused. What does the program do next?

Does it go back to the for statement to check which (term)/element this is to make sure it is less then 102. 

Also when I specify the range to be 102 does it do the action once and then 102 times more basically list the number 103 times) or does it do it 102 times)?

What I am basically asking is if I need to find the 103rd element why do i specify range=102, not range =103

Answer: 
Let's expand the for loop and see what happens:

```
a = 0    
b = 1     # this is the first fibonacci number

# First iteration of for loop
c = a + b # c is now 1, the second fibonacci number
a = b     # a is now 1
b = c     # b is now 1

# Second iteration
c = a + b # c is now 2, the third fibonacci number
a = b     # a is now 1
b = c     # b is now 2

# Third iteration
c = a + b # c is now 3, the fourth fibonacci number
a = b     # a is now 2
b = c     # b is now 3

# Fourth iteration
c = a + b # c is now 5, the fifth fibonacci number
a = b     # a is now 3
b = c     # b is now 5

# Remaining 98 iteration omitted

```

You see that after 4 iterations we have in `c` the 5:th fibonacci number. After 102 iterations `c` will hold the 103:d fibonacci number. That is why you are using `range(102)` and not `range(103)`. If you wanted your fibonacci series to start with 0 ([as it sometimes does](http://en.wikipedia.org/wiki/Fibonacci_number)), i.e. `0, 1, 1, 3, 5`, you would need to use `range(101)`.

The python for loop iterates over a sequence until the sequence is exhausted, or the for loop is prematurely exited with the `break` statement. `range(5)` creates a list of 5 elements: `[0, 1, 2, 3, 4]`, which, when used with the for loop, causes it to repeat 5 times. The loop body in the following example is therefore evaluated 5 times:

```
sum = 0

for i in range(5):
  sum = sum + i

print sum

```

We just calculated the fifth [Triangle number](http://en.wikipedia.org/wiki/Triangular_number): 10 

More on python for loops: 
<https://wiki.python.org/moin/ForLoop>
`range` is a function that returns a list of integers. If you specify a single argument `n`, you get all integers from 0 through `n-1`.

A statement of the form `for x in y: <do something>`, where `y` is iterable, iterates over every element in `y`. For each such element `z`, it binds the variable `x` to `z` and then executes the body of the loop one time.

So the line `for i in range(102)` executes everything inside the loop one for each integer between 0 and 101. NB: you aren't actually referencing the variable `i` inside your loop, so you could also write `for _ in range(102)`.

Regarding the block inside the loop, it goes roughly like this:

* set `c` equal to the sum of `a` and `b`
* set `a` to the value of `b`
* set `b` to the value of `c`

So each time you iterate, you find the next number, store it in `c`, and then update your state variables `a` and `b`. `a` and `b` hold the last two fibonacci numbers.

If you really want the 103rd fibonacci number, there is a bug in your program - do you see it?