aeonsky Posted December 3, 2008 Share Posted December 3, 2008 private Node test(String symbol) { Node retval = null; Node node1 = portfolio; do { if(node1.next == null) break; if(((Stock)node1.item).getSymbol().equals(symbol)) { retval = node1; break; } node1 = node1.next; } while(true); return retval; } I was studying some code and had a question which I couldn't find the answer to. This is the line... while(true); While what is true is it executing the code? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/135272-quick-java-help/ Share on other sites More sharing options...
aeonsky Posted December 3, 2008 Author Share Posted December 3, 2008 Never mind, sorry! It seems it just keeps checking the nodes and increments the nodes one by one and breaks eventually. Am I right? Quote Link to comment https://forums.phpfreaks.com/topic/135272-quick-java-help/#findComment-704560 Share on other sites More sharing options...
GingerRobot Posted December 3, 2008 Share Posted December 3, 2008 The do...while loop in the above code is an infinite loop - it will execute indefinitely, unless it is explicitly broken out of with a break statement. So yes, that loop will run until either of the two if statements evaluate to true. I've never done any java, but i would guess that the function searches some sort of list structure. Quote Link to comment https://forums.phpfreaks.com/topic/135272-quick-java-help/#findComment-705097 Share on other sites More sharing options...
DarkWater Posted December 3, 2008 Share Posted December 3, 2008 Well, since all that a while does is check if a condition evaluates to boolean true and then executes a block if it does, putting true as the condition is guaranteed to run the loop infinitely unless explicitly broken out of. while(1) would do the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/135272-quick-java-help/#findComment-705465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.