# Thread: Matlab question! Help! Infinite loop.

1. ## Matlab question! Help! Infinite loop.

I can't seem to figure out this question:

N = 1;
while N < N + 1
N = N*10
end

All variables are IEEE double precision. Will the code above result in an infinite loop?

I believe this will be a infinite loop because the value N is always going to be compared to a value 1 unit greater than itself, but what does that its double precision have to do with anything?

Thanks,
Naruto

2. And why you did that?

What is the goal of this loop??

Yes, it is infinite loop because the condition N < N+1 is always satisfied.

Double precision is common for decimal point numbers, and double precision means that there the numbers are represented by 64 bits.

Regards.

3. There is no goal. It was simply a question on a practice exam.

BTW thank you for your response.

4. Originally Posted by naruto
There is no goal. It was simply a question on a practice exam.

BTW thank you for your response.
Regarding IEEE double precision: I'm guessing MATLAB uses arbitrary precision integers, meaning if you need a very large integer, there will be memory allocated accordingly; but in other languages, if for example you use signed 32-bit integers, then it's possible for N < N+1 to fail. So in Java the maximum value for a 32-bit integer is 2^31-1 = 2,147,483,647, and if you add 1 to it you get -2^32 = -2,147,483,648. This is called integer overflow.

Anyway that's my guess as to why they put IEEE double precision in there, because I don't think N < N+1 can fail in that instance, in any language.