1. ## Stopping a Loop

I have a function that takes the sum of 1/n/(n+1). I want my loop to keep adding the numbers together UNTIL the difference between consecutive numbers is less than or equal to 0.0000001. I have no idea how to tell the loop to look at only the difference between consecutive numbers, not just the number itself. Does anyone know how to tell a loop to stop in this case? Thanks!

2. A kind of fool proof method, but not very elegant way is to go

Code:
```while(1){

do something....

if (difference<=0.0000001) break;
}```
or better...

Code:
```do {

//do something....calculate sum and difference , increment n

} while((difference<=0.0000001); // not sure is you need a semicolon here but the compiler will advise!!```
I bet they produce pretty much the same code anyway!!

3. Originally Posted by Catman188
I have a function that takes the sum of 1/n/(n+1). I want my loop to keep adding the numbers together UNTIL the difference between consecutive numbers is less than or equal to 0.0000001. I have no idea how to tell the loop to look at only the difference between consecutive numbers, not just the number itself. Does anyone know how to tell a loop to stop in this case? Thanks!
You can use while loop like this:
Code:
```while(delta >threshold)
{
//update n
//compute something
//update delta

}```