0
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

Edited by happygeek: fixed formatting

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by VernonDozier
0

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?

Edited by happygeek: fixed formatting

0

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

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.