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());

23rd Sep 2020, 3:01 PM
SH S
SH S - avatar
1 Odpowiedź
+ 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 .
23rd Sep 2020, 5:11 PM
Akash Kumar S
Akash Kumar S - avatar