13,087,235 members (54,943 online)
Rate this:
See more:
```Dim li_Term As Integer
Dim li_a As Integer = 0
Dim li_b As Integer = 1
Dim li_fib As Integer = 0
Dim li_c As Integer
While li_fib <= 9
TextBox1.Text = TextBox1.Text + li_Term.ToString + ControlChars.NewLine
li_a = li_b
li_Term = li_a + li_b
li_c = li_c + 1
End While```
Posted 9-Jul-12 0:10am
La Moth484

Rate this:

## Solution 1

It will take a long time.
In fact it will never return.

Since you don't change the value of li_fib inside the loop, the while condition will always be met.
Perhaps if you add the line
`li_fib = li_fib + 1`
inside the loop, it might work better...
Tefo Sean Mothowe 9-Jul-12 6:27am

Ok but after I midified the code it is like this and prints the series as
0
2
2
2
2
2
2
2
2
2
OriginalGriff 9-Jul-12 6:37am

I didn't say your code was right! :laugh:
It isn't, which is why you have a problem.
Now starts the fun bit: debugging!
I could just tell you what the problem is, but this is a nice, simple piece of code so it should be pretty easy for you to work it out. And at the same time, learn to use the most powerful tool in your coding arsenal: The Debugger.

Start by putting a breakpoint on the first line in the loop. (See the VS menu under Debug - just put the cursor in the line, and "toggle breakpoint" - a red dot will appear to the left of the line.)

Run your program, and it will stop when it hits the breakpoint. You can then look at your data, and single step through each line.
How does your data change each time?
Rate this:

## Solution 3

Try this one.. It works..

```
Dim li_a As Integer = 1
Dim li_b As Integer = 1
Dim li_fib As Integer = 0
TextBox1.Text = li_b.ToString + ControlChars.NewLine
While li_fib <= 9

TextBox1.Text = TextBox1.Text + li_b.ToString + ControlChars.NewLine
li_b = li_b + li_a
li_a = li_b - li_a
li_fib = li_fib + 1

End While
```
Rate this:

## Solution 2

[This is not an answer, should be removed — SA]

```Dim li_Term As Integer
Dim li_Term As Integer = 1
Dim li_Termprev As Integer = 0
Dim li_TempBuff = 0
Dim li_fib As Integer = 0
While li_fib <= 9
li_TermBuff = li_Term
li_Term = li_Term + li_Termprev
li_Termprev = li_TermBuff
TextBox1.Text = TextBox1.Text + li_Term.ToString + ControlChars.NewLine
li_fib = li_fib + 1
End While```
v4

Top Experts
Last 24hrsThis month
 Jochen Arndt 210 RyanDev 178 Graeme_Grant 130 Karthik Bangalore 120 OriginalGriff 116
 OriginalGriff 3,123 Graeme_Grant 1,529 ProgramFOX 1,377 Jochen Arndt 1,300 ppolymorphe 1,257