Results 1 to 3 of 3
  1. #1
    pateln is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default Breaking do while loop

    I'm trying to figure what i need to put to break this do while loop. This program should only respond to a, b, or c and if the user puts any other letter the loop will end.
    P.S
    I'm new at this whole java forums thing so sorry if I do anything wrong. Also for some reason my computer, an imac, won't let me upload any attachments to this post, so i'm just going to past the code underneath this.


    package c5r2abc;
    import cs1.Keyboard;
    public class C5R2abc {

    public static void main(String[] args) {
    //Variables
    int count = 0, count1 = 0, count2 = 0;
    char choice;

    //Enter a letter
    System.out.println("Enter either \'a\', \'b\', or \'c\' when prompted");
    System.out.println("enter any other letter to quit");
    System.out.println("\nEnter letter: ");
    choice = Keyboard.readChar();

    //Do while loop
    do{
    if(choice == 'a'){
    System.out.println("A is for apple.");
    count = count + 1;
    }
    if(choice == 'b'){
    System.out.println("B is for baby.");
    count1 = count1 + 1;
    }
    if(choice == 'c'){
    System.out.println("c is for Chicago.");
    count2 = count2 + 1;
    }
    System.out.println("\nEnter letter: ");
    choice = Keyboard.readChar();
    }while(choice != )
    }
    }
    Last edited by pateln; 09-24-2012 at 10:02 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Breaking do while loop

    Moved from the NetBeans section.

    Please go through BB Code List - Java Programming Forum and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default Re: Breaking do while loop

    Have you tried a break statement?

Similar Threads

  1. Calculating Mileage & Breaking For Loop
    By dgoff267 in forum New To Java
    Replies: 5
    Last Post: 02-22-2012, 12:51 AM
  2. Breaking out a timer loop
    By musico in forum New To Java
    Replies: 6
    Last Post: 06-23-2011, 08:29 PM
  3. breaking up
    By smray7 in forum New To Java
    Replies: 2
    Last Post: 10-31-2010, 07:58 AM
  4. breaking out of while loop
    By mac in forum New To Java
    Replies: 5
    Last Post: 05-18-2010, 03:21 PM
  5. Breaking up of array
    By agarwal_srushti in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 07:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •