Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:56:40+00:00 2026-06-15T12:56:40+00:00

this is the code that i have but i have to admit i have

  • 0

this is the code that i have but i have to admit i have become a bit code blind and cant seem to see the problem eventhough i feel it is an easy one. Any help would be much appreciated. Thank you in advance.

   do{
        System.out.println("Command:");
        scan = new Scanner (System.in);

        String line;                        

        line = scan.nextLine();

        String[]SplitUpText;

        SplitUpText=line.split(" ");

        Command = SplitUpText[0];

        int param1=-1, param2=-1;

        if (Command.compareTo("move")==0)
        {
            if (SplitUpText.length>1)
            {
                param1=Integer.parseInt(SplitUpText[1]);
                if(SplitUpText.length>2)
                {
                    param2=Integer.parseInt(SplitUpText[2]);
                }
            }g.moveTo (param1, param2);


        }else if(Command.compareTo("circle")==0){

            if (SplitUpText.length>1)
            {
                param1=Integer.parseInt(SplitUpText[1]);
            }g.circle (param1);
        }else if(Command.compareTo("line")==0){
            if (SplitUpText.length>1)
            {
                param1=Integer.parseInt(SplitUpText[1]);
                if(SplitUpText.length>2)
                {
                    param2=Integer.parseInt(SplitUpText[2]);
                }
            }g.lineTo (param1, param2);
        } else {
            System.out.println("Invalid Command");
        }

    } while (Command.compareTo ("end")!=0);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:56:41+00:00Added an answer on June 15, 2026 at 12:56 pm

    It’s generally best practice to avoid it (by adding a condition to the while expression instead), but if you want to end the loop prematurely, you can use break;

    Here’s a simpler example:

    int i;
    
    i = 0;
    do {
        ++i;
        System.out.println("Before: " + i);
        if (someSpecialCondition) {
            break;
        }
        System.out.println("After: " + i);
    }
    while (i < 5);
    

    Let’s suppose the special condition occurs when i has just become 3, the output would be:

    Before: 1
    After: 1
    Before: 2
    After: 2
    Before: 3

    Note how the break terminated the loop. It can be used with all kinds of loops (do..while, while, and both kinds of for).

    If you have nested loops and need to break the outer one from within the inner one, you should probably refactor that code into sub-methods. BUT, if you don’t want to refactor, you can use a directed break:

    int i, j;
    
    outerLoop: for (i = 0; i < 5; ++i) {
        for (j = 0; j < 5; ++j) {
            if (i == 2 && j == 2) {
                break outerLoop;
            }
        }
    }
    

    There, outerLoop labels the outer loop, and break outerLoop causes both the inner loop and the outer loop to terminate. Again, though, if you get into doing this, it’s probably time to refactor.

    More from the JLS: http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.15

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that runs but never stops. class A { public static
I have this code that works in a unit test but doesn't work when
I have this code that shows all the images inside 'images' directory but it
I have no idea what this means. But here is the code that it
So I have to admit, that I had this code working perfectly up until
I have to admit that having not even tried to code this myself this
Challenge: I have this code that fails to compile. Can you figure out what's
So I have this code that checks 4 parameters (author, title, keyword and subject)
hello I have this code that use to sort a datatable. Dim sortingIndex As
I have this code that I've edited: http://pastebin.com/vrqHek6S I've put in comments where I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.