I am trying to change a program from an IF loop to a WHILE loop. The program started in Ch.05. It was modified in Ch.06 to an IF loop & now must be changed to a WHILE.
I got it down to 2 errors and am totally lost. Maybe a fresh set of eyes can point me in the right direction?
I've attached all 3 so you may see the progression.
Any assistance is greatly appreciated.

Recommended Answers

All 6 Replies

You are pretty close. The errors are because you still have mismatched braces on the loop blocks. You left the do() statement in, which is messing up your while() block. Walk through the flow of that while() block and you'll see that you need to prompt for another customer name at the end of it so the sentinel while() test can evaluate whether you want to continue or stop.

It's amazing what a fresh set of eyes can see.
I will be attempting it again tomorrow with the info you provided.
Thanks for your assist. Hopefully I'll be refeshed and 'clear-minded' to attempt this tomorrow.

Somebody save me i need someone to tell me how to create an if else loop for 10 different numbers

I'd suggest you post this in a new thread rather than bouncing up an only slightly-related one from two years ago. When you do that, you might want to me a little more specific about what you want to do, and show us what you've tried and what's not working about it. That might get you a better response.
Before you do that, though, read the sticky threads at the top of this forum - if you haven't read Eric Raymond's piece on "How to Ask Questions the Smart Way" you're not done reading yet.

class doWhileDemo 
    {
        public static void main(String arg[])
        {
            int x = 1;
            int y = 2*x + x;
            
            
            do {
                System.out.println("y=:"+ y);
                ++x;
               }
               while(x<10);
               
        }
    }

am trying to parse the value of x after addition to the operation for y but it aint working

If you didn't read my previous post, please read my previous post, and then start a new thread to ask your question.

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.