Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: nested do while loop

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question nested do while loop

    I am very new at java and just trying to learn it on my spare time and I'm doing do-while loops and I am having trouble understanding the below code if somebody could help me out that would be great.


    public class help {
    public static void main (String args[])
    throws java.io.IOException {
    char choice, ignore;
    do{
    System.out.println ("Choose one:");
    System.out.println("1. if");
    System.out.println("2.switch");

    choice = (char) System.in.read();
    do{
    ignore = (char) System.in.read();
    }while(ignore != '\n');
    }while (choice < '1'| choice >'2');

    switch(choice){
    case '1':
    System.out.println("if");
    break;
    case '2':
    System.out.println("switch");
    break;
    }
    }
    }

    Whats the point of the block?
    do{
    ignore = (char) System.in.read();
    }while(ignore != '\n');

    It makes no difference in the program wither i delete this block or keep it

    Also can somebody explain how while (choice < '1'| choice >'2'); translates? I would assume it would be while (choice >= '1'| choice =<'2');?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: nested do while loop

    Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

    Please post your code correctly.

Similar Threads

  1. Nested For...each Loop?
    By melki0795 in forum Java Theory & Questions
    Replies: 11
    Last Post: January 29th, 2014, 09:36 AM
  2. nested for loop
    By yuli in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 11th, 2013, 07:52 PM
  3. Nested For Loop!
    By samadniz in forum Object Oriented Programming
    Replies: 3
    Last Post: September 3rd, 2012, 04:03 PM
  4. Nested for loop
    By wolf_fcknHaley33 in forum Loops & Control Statements
    Replies: 2
    Last Post: May 23rd, 2012, 08:49 AM
  5. nested loop
    By b109 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 30th, 2010, 10:05 AM

Tags for this Thread