Results 1 to 10 of 10
- 01-31-2012, 10:02 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 57
- Rep Power
- 0
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
This is the output.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"); } } } }
I dont seem to get int the last if statement.Java Code:sortTypes enterd Types found searching for:Tansducer Processing Initialized Processing SIO Processing UTB Processing Battery Processing Tansducer Processing UTBHV Processing Release
Is ther a way to stop when the string eT is equal to the string Selected?
- 01-31-2012, 11:05 PM #2
Member
- Join Date
- May 2011
- Posts
- 84
- Rep Power
- 0
Re: Stopping for "loop" when conditions are met
Maybe break out of the loop when if() condition is met?
- 02-01-2012, 03:59 AM #3
Re: Stopping for "loop" when conditions are met
Just put in a break statement.
- 02-01-2012, 06:59 AM #4
Member
- Join Date
- Dec 2011
- Posts
- 57
- Rep Power
- 0
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.
- 02-01-2012, 09:10 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,374
- Blog Entries
- 7
- Rep Power
- 17
Re: Stopping for "loop" when conditions are met
Your data doesn´t seem to contain the value ´T(r)ansducer'?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-01-2012, 09:27 AM #6
Member
- Join Date
- Dec 2011
- Posts
- 57
- Rep Power
- 0
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.
- 02-01-2012, 09:30 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,374
- Blog Entries
- 7
- Rep Power
- 17
Re: Stopping for "loop" when conditions are met
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-01-2012, 09:33 AM #8
Member
- Join Date
- Dec 2011
- Posts
- 57
- Rep Power
- 0
Re: Stopping for "loop" when conditions are met
(scratch bald head)
When I do like this:
It stops (obviously) but still not the result I wan'tJava Code:if(eT.equals(eT)){
EDIT
Result from Jos output:
It should be the same as the string selected is actually parsed from the same document..Java Code:Types found searching for:Battery Processing [Initialized] Processing [SIO] Processing [UTB] Processing [Battery] Processing [Tansducer] Processing [UTBHV] Processing [Release]
Last edited by KarlNorway; 02-01-2012 at 09:35 AM.
- 02-01-2012, 09:36 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,374
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-01-2012, 09:37 AM #10
Member
- Join Date
- Dec 2011
- Posts
- 57
- Rep Power
- 0
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
-
Got struck with this :- " Exception in thread "main" java.lang.NullPointerException"
By Vermont in forum New To JavaReplies: 5Last Post: 12-21-2011, 06:44 PM -
Mutliple JPanel's with an enhanced "for" loop
By javaman1 in forum New To JavaReplies: 4Last Post: 10-23-2010, 12:18 AM -
An "if" statement inside a "for" loop?
By soccermiles in forum New To JavaReplies: 18Last Post: 04-20-2010, 03:44 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks