# Unending Loop Issue? Can't find it.

• March 4th, 2011, 06:09 PM
computerguy38
Unending Loop Issue? Can't find it.
Although I think this is an issue with my loops structure/conditions this could also be an issue with how Java does arithmetic. I'm sure this is probably simple but I can't find it right now. :(
The polynomial object is composed of an array of size 100 which stores the coefficients of a polynomial in index locations corresponding to the power of each respective term. The purpose of this code is to create a new polynomial object which is the result of multiplying two polynomials.
I'm pretty sure that the loop is not ending but I'm not sure why. The initial S.o.ps of i+j values are what I expect but then they go into enormous negative numbers and I have no idea why.
Code Java:

``` public Polynomial mult(Polynomial p) throws ExponentOutOfRangeException { Polynomial multiPolynomial = new Polynomial();     //Start testcode System.out.print("this polynomial "); this.displayPolynomial(); System.out.print("p polynomial "); p.displayPolynomial(); //End testcode     for(int i = 0; i < 99; i++) { for(int j = 0; j < 99; i++) { if((i+j) < MAX) { multiPolynomial.polyArr[i + j] = multiPolynomial.polyArr[i + j] + (this.polyArr[i] * p.polyArr[j]); } } } // Multiplies polynomial p to this polynomial without modifying this // polynomial and returns the result. // Precondition: None. // Postcondition: The returned polynomial is the product of this // and p. Both this and p are unchanged. // Throws: ExponentOutOfRangeException if exponent is out of range. return multiPolynomial; }```
By the way,
• March 4th, 2011, 07:02 PM
computerguy38
Re: Unending Loop Issue? Can't find it.
Thanks to whoever fixed the way the code displays here. I was looking up the necessary tags just now. :) Anyone see the problem? Maybe I should include more code...
• March 4th, 2011, 07:03 PM
helloworld922
Re: Unending Loop Issue? Can't find it.
Quote:

Code Java:

`for(int j = 0; j < 99; i++)`

You're incrementing i in the j loop, not j :P
• March 4th, 2011, 07:04 PM
javapenguin
Re: Unending Loop Issue? Can't find it.
You seem to be incrementing i twice.

Perhaps you should change it to j++;

As it is, i is being incremented twice and j is stuck at 0.

Musta posted at same time as helloworld922.

Oh well.
• March 4th, 2011, 07:22 PM
computerguy38
Re: Unending Loop Issue? Can't find it.
Omigosh, how embarrassing! I looked at the problem is sooo many ways and I missed that simple item. I guess that's why you ask other people to look at code. Thanks guys! :D