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: How do I make a break in this?

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do I make a break in this?

    if (number1 + 8 == number2 || number1 - 8 == number2){
    if (name1.equals(name2)){
    if (cod1 == cod2){
    if (some1.equals(some2)){
    System.out.println("They're in the same group");
    }

    System.out.println("They are in the same column");;
    }

    System.out.println("They are in the same section");
    }

    System.out.println("They are in the same subgroup");
    }

    else{
    System.out.println("They are different");
    }
    }
    }

    How could I change this so that I only get one message at the end? Right now it gives all the messages or just the They are different. I know I can't put an actual break since this isn't a loop, but what action could I take in this problem? Would I have to rewrite it? Thank You for the help.


  2. #2
    Member
    Join Date
    Aug 2013
    Posts
    95
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Default Re: How do I make a break in this?

    at the bottom of your segment of code you can do this... Take out the print statements in your if statement blocks and add the printing code at the end.

    if (some1.equals(some2))
    print blah blah
    else if (cod1 == cod2)
    print blah blah
    else if (name1.equals(name2))
    print blah blah
    else if (number1 + 8 == number2 || number1 - 8 == number2)
    print blah blah

Similar Threads

  1. [SOLVED] Continue and break statements
    By ///M Dood in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 22nd, 2013, 03:46 PM
  2. where to break array sorting?
    By BITmixit in forum What's Wrong With My Code?
    Replies: 12
    Last Post: December 13th, 2011, 09:46 AM
  3. Help with interrupting a loop without break or continue
    By mwr76 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 11th, 2011, 08:51 PM
  4. Break it down
    By [Kyle] in forum Java Theory & Questions
    Replies: 5
    Last Post: September 19th, 2009, 09:04 PM

Tags for this Thread