Jump to content

Quick Java help


aeonsky

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/135272-quick-java-help/
Share on other sites

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/135272-quick-java-help/#findComment-705097
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/135272-quick-java-help/#findComment-705465
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.