while (firstNodeNeedsToGo(text))
        {
            removeFirstNode();
            nodeRemoved = true;
        }

can someone rewrite this while loop into an if - then loop or any other code you have , this will help greatly toward my upcoming test

Recommended Answers

All 3 Replies

Not sure what you mean by "if then loop". "if" statements aren't loops. You only go through them once. What are you asking precisely?

so an if-then statement cant go on forever? an while loop cant be rewritten as if-then statement?

Well, if you wanted to make an "if" statement go on forever, I guess you could do something like this:

if (if condition)
{
     while (2 + 2 == 4)
     {
           // code
     }
}

That'd go on forever, but it's really a cheat since it's the while loop that's going on forever and the "if" evaluation still only gets executed once. Can't think of any way other than calling a recursive function that the "if" statement is in to make the "if" occur more than once, like this:

void foo ()
{
      if (if condition)
      {
            // code
            foo ();
       }
}

Unless you use a GOTO type statement, which I don't think exists in Java.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.