# Thread: got stuck in simple coding process. how to initialize "any value"

1. ## got stuck in simple coding process. how to initialize "any value"

hi guys

in order to calculate some logarithm approximation I need to make a variable, say s, search through the whole integer numbers.

I believe something like this isn't much of help?

Code:
```int s;
for {;;s++){

code...

}```
since the variable needs to be initialized right?

any ideas how to go through all the numbers?

2. All the integers would be
for ( int i = INT_MIN ; i <= INT_MAX ; i++ )

But most people trying to evaluate an infinite progression tend to stop after a few iterations anyway.
Calculating even say the 100th decimal place, when a double has only 15 digits of precision is pointless.

3. Originally Posted by Salem
All the integers would be
for ( int i = INT_MIN ; i <= INT_MAX ; i++ )
Except that i <= INT_MAX is never false.

If you don't need negative values then you can declare your variable as unsigned, and then go up to about 4.2 billion rather than only 2.1 billion.
But really, how high do you need to go?

4. Originally Posted by Salem
All the integers would be
for ( int i = INT_MIN ; i <= INT_MAX ; i++ )
That would cause an infinite loop at best, or undefined behaviour (when an int with value INT_MAX is incremented).

If you want to do something over all integers that can be represented on your target system, one technique would be

Code:
```for (i = INT_MIN; ; ++i)    /*  note no termination condition here */
{
/* do something with i */

if (i == INT_MAX) break;    /*  But we break out after finishing with INT_MAX */
}```
This is one of those obscure cases that is difficult to achieve without a goto (a break is a goto by another name).