Originally posted by: RMSistight
Originally posted by: n0cmonkey
Originally posted by: RMSistight
Originally posted by: n0cmonkey
What don't you get exactly?
Well..the part where it says:
C = A + B
A = B
B = C
My friend told me to write it out...which I did...but I don't understand it.
Read my edit.
Ok I read your edit...and still having trouble grasping it. I'm sorry for being an idiot but could you explain it in English line for line of the code?
From what I understand is:
1 + 1 = C so C = 2
A = B (1 = 1?)
B = C (1 = 2?)
A, B, and C are "variables". That is, their values vary over time. Rather than reading "A equals B", read it as "A gets assigned the value of B".
Remember, the values of A, B, and C will change each pass through the loop!
See if this helps:
--------------------------------------
A = 1
B = 1
Print A
Print B
For I = 1 To 5
C = A + B
A = B
B = C
Print C
Next
--------------------------------------
Here are our values when we start:
A= 1 (A is assigned the value "1")
B= 1 (B is assigned the value "1")
(C is currently undefined)
In our first pass of the for loop we have this:
C = A + B (C is assigned the value 1 + 1, which is 2)
A = B (A is assigned the value of B, which is 1)
B = C (B is assigned the value of C, which is 2)
We print C, which is "2"
In the second pass of the loop:
C = A + B (C is assigned the value 1 + 2, which is 3)
A = B (A is assigned the value of B, which is 2)
B = C (B is assigned the value of C, which is 3)
We print C, which is "3"
In the third pass of the loop:
C = A + B (C is assigned the value 2 + 3, which is 5)
A = B (A is assigned the value of B, which is 3)
B = C (B is assigned the value of C, which is 5)
We print C, which is "5"
In the fourth pass of the loop:
C = A + B (C is assigned the value 3 + 5, which is 8)
A = B (A is assigned the value of B, which is 5)
B = C (B is assigned the value of C, which is 8)
We print C, which is "8"
In the fifth pass of the loop:
C = A + B (C is assigned the value 5 + 8, which is 13)
A = B (A is assigned the value of B, which is 8)
B = C (B is assigned the value of C, which is 13)
We print C, which is "13"
We get the following output
1
1
2
3
5
8
13
I hope this helps.
Dave
Edit: dumb typo