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 4 of 4

Thread: Intersection of two loops

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Intersection of two loops

    Hi everybody!!!
    I want to get intersection of two loops. For example
    class uniqueKey{
    	public static void main(String args[]){
    		for(int i=1;i<10;i++){
    			if(i==5 || i==6 || i==7)
    				continue;
    			System.out.println(i);
    		}
    	}
    }
    Out put of this code is
    1
    2
    3
    4
    8
    9
    Now scenario is something like this:
    Suppose 5,6 and 7 are coming from database in a while loop and we want to print only those values that are not coming from database say from 1 to 10. I tried a lot but no success. Plz help me in this regard.....


  2. #2
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Intersection of two loops

    while(database input has elements) {
    read the element;
    if (i == element) contunue mainLoop;
    }

    Of course, the for should be labeled with mainLoop label then.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Intersection of two loops

    Sorry could't get your point. Please make it clear. It is little bit confusing. Thanks

  4. #4
    Member angstrem's Avatar
    Join Date
    Mar 2013
    Location
    Ukraine
    Posts
    200
    My Mood
    Happy
    Thanks
    9
    Thanked 31 Times in 29 Posts

    Default Re: Intersection of two loops

    Inside the "for" loop, organize another loop for reading the database. For each read element, check whether specified condition (in your case, i == element) is true. If it is true, continue the for loop.

Similar Threads

  1. Union and Intersection methods (SetADT)
    By jason3460 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 7th, 2013, 11:22 AM
  2. INTERSECTION OF TWO LIST
    By muhammad waqar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 5th, 2013, 08:09 AM
  3. Not sure what kind of loop I need to use for an intersection program
    By sessypeanut in forum Loops & Control Statements
    Replies: 4
    Last Post: December 21st, 2012, 11:11 PM
  4. For loops
    By JCTexas in forum Loops & Control Statements
    Replies: 4
    Last Post: September 21st, 2011, 05:43 PM
  5. help with loops
    By kidza12 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 26th, 2011, 11:42 PM