Results 1 to 10 of 10
  1. #1
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Stopping for "loop" when conditions are met

    Hi

    I have a small issu here.

    I want to have something happen when the condition is met.

    Here is my code
    Java Code:
    void sortTypes() {
    			Element docEle = dom.getDocumentElement();
    			
    			System.out.println("sortTypes enterd");
    			
    			
    			NodeList nlT = docEle.getElementsByTagName("Type");
    			System.out.println("Types found \n searching for:" + Selected);
    			
    			if(nlT != null && nlT.getLength() > 0) {
    				for(int i = 0 ; i < nlT.getLength();i++) {
    					
    					//get the employee element
    					Element elT = (Element)nlT.item(i);
    					
    					//get the Employee object
    					String eT = getType(elT);
    					
    					System.out.println("Processing \n" + eT);
    					
    					
    					if(eT.equals(Selected)){
    						
    						
    	        	System.out.println(Selected + "Found");
    	        	
    	        	
    	           
    	            }
    					}
    				}
    	    }
    This is the output.
    Java Code:
    sortTypes enterd
    Types found 
     searching for:Tansducer 
    Processing 
    Initialized
    Processing 
    SIO
    Processing 
    UTB
    Processing 
    Battery
    Processing 
    Tansducer
    Processing 
    UTBHV
    Processing 
    Release
    I dont seem to get int the last if statement.
    Is ther a way to stop when the string eT is equal to the string Selected?

  2. #2
    Eleeist is offline Member
    Join Date
    May 2011
    Posts
    84
    Rep Power
    0

    Default Re: Stopping for "loop" when conditions are met

    Maybe break out of the loop when if() condition is met?

  3. #3
    Shai-Softİ's Avatar
    Shai-Softİ is offline ShaiSoftİ
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default Re: Stopping for "loop" when conditions are met

    Just put in a break statement.

  4. #4
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Re: Stopping for "loop" when conditions are met

    Ok will try that

    thanks for helping

    Dosent work for me..
    Last edited by KarlNorway; 02-01-2012 at 08:59 AM.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,006
    Blog Entries
    7
    Rep Power
    20

    Default Re: Stopping for "loop" when conditions are met

    Your data doesn´t seem to contain the value ´T(r)ansducer'?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Re: Stopping for "loop" when conditions are met

    It dosen't matter what I choose. It never stops

    It actually looks like I dont get inside the last IF statement.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,006
    Blog Entries
    7
    Rep Power
    20

    Default Re: Stopping for "loop" when conditions are met

    Quote Originally Posted by KarlNorway View Post
    It dosen't matter what I choose. It never stops

    It actually looks like I dont get inside the last IF statement.
    Print out the values found as:

    Java Code:
     System.out.println("Processing \n[" + eT+"]");
    and check if the value(s) contain leading or trailing spaces ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Re: Stopping for "loop" when conditions are met

    (scratch bald head)

    When I do like this:
    Java Code:
    	if(eT.equals(eT)){
    It stops (obviously) but still not the result I wan't


    EDIT

    Result from Jos output:

    Java Code:
    Types found 
     searching for:Battery 
    Processing 
    [Initialized]
    Processing 
    [SIO]
    Processing 
    [UTB]
    Processing 
    [Battery]
    Processing 
    [Tansducer]
    Processing 
    [UTBHV]
    Processing 
    [Release]
    It should be the same as the string selected is actually parsed from the same document..
    Last edited by KarlNorway; 02-01-2012 at 09:35 AM.

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,006
    Blog Entries
    7
    Rep Power
    20

    Default Re: Stopping for "loop" when conditions are met

    Did you check if there were trailing spaces in your data? (see my previous reply). Also check what the String.trim() method can do for you.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    KarlNorway is offline Member
    Join Date
    Dec 2011
    Posts
    57
    Rep Power
    0

    Default Re: Stopping for "loop" when conditions are met

    I found that the string selected actually has a trailing white space..

    Fixing now.

    Removing a space in the place where i build up the array to go into a combo (that spits out selected string) helped...

    Thaks a lot folks.
    Last edited by KarlNorway; 02-01-2012 at 09:40 AM.

Similar Threads

  1. Replies: 5
    Last Post: 12-21-2011, 06:44 PM
  2. Mutliple JPanel's with an enhanced "for" loop
    By javaman1 in forum New To Java
    Replies: 4
    Last Post: 10-23-2010, 12:18 AM
  3. An "if" statement inside a "for" loop?
    By soccermiles in forum New To Java
    Replies: 18
    Last Post: 04-20-2010, 03:44 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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