Stuck while loop
Having a little trouble with my while loop, as it runs but gets stuck.
Basically, I have a list of integers which are in order of size, and several or many could be the same, and I want to find all the ones that are the same. So I am taking the first number, comparing it with the second, then the third, until it finds one that is different, and then moving on.
I've run some debugging tests and my code is finding the first 2 integers that are the same, moving onto my second while loop, finding that the second and third numbers are not the same, but for some reason isn't moving on. It doesn't go through the second while loop if b is null or i isn't equal to b, but then it goes back to the top of the while loop and goes round and round in the same way.
This is my code:
I was certain my code is correct so I am thinking I have made a small mistake which is causing the loop to get stuck. Does anybody have any suggestions?
Int i = startingInteger; //i is the first integer in my list
while (i.next != null) //while there is a second integer
if(i == i.next) //if first and second values are the same
int b = i.next;
while (b != null && (i == b))
b = b.next;
i = i.next; //move on to the next word
Does your code compile? You seem to be trying to get a field from a primitive, an int.
I suggest you create and post an SSCCE, one that is small, compiles, and shows your error. Do this and you'll likely get faster, better help.
Sorry, my mistake. I meant to type Int because I have created my own Int class that stores integer values and these are stored in a list.
I have just realised my own problem as I edited my post, that I have used 'else' when I shouldn't have because it should set i to i.next when the while loop is not satisfied.
So I have solved my own problem for once, sorry to waste your time.