0
Need help -> Convert do-while loop to while loop
ââ LLnode helpPtr=myList.getHead(); do { if (helpPtr.getNext()!= null) { helpPtr=helpPtr.getNext(); } else{ helpPtr.setNext(myList.getHead()); } } while (helpPtr.getNext()!=myList.getHead()); đthis how I convert the do while to while loop. It is correct?? ââ LLnode helpPtr=myList.getHead(); while (helpPtr.getNext()!= null){ helpPtr=helpPtr.getNext(); } helpPtr.setNext(myList.getHead());
1 Answer
+ 1
Seems like helpPtr.getNext() returns the next value , so it seems there is an error in your program . Using helpPtr.getNext() inside the loop condition check will advance the next call to same function to the next value .
So you have to store that return value in a variable to check condition instead of calling the next function again and again . Since , it will advance to next element in every call .
Sry If it's not the relevant answer .