Results 1 to 4 of 4
- 05-13-2011, 06:04 PM #1
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
While loop does not function properly
Hi guys. I have a simple problem with my While loop but I was looking into it long time and I don't understand why loop goes over again all the time and never ends. As you see cont = "t", but later I enter "n" with keyboard, but loop still goes on. I even made this line:
just to make sure how does cont looks like just before loop ends and it says that cont is "n", but the while loop never ends. Inputt is a method I made to enter strings but it works well.Java Code:System.out.println(cont);
Java Code:String cont = "t"; while (cont != "n"){ System.out.println("Enter new part name:"); partName2 = inputt(); System.out.println("Do you want to enter aditional parts? y/n"); [B]System.out.println(cont);[/B] // cont is "t" here cont = inputt(); [B]System.out.println(cont);[/B] // cont is "n" here if I enter "n". }
- 05-13-2011, 06:05 PM #2
== does not work as expected on Strings; they check if they are the same String object, not if they represent the same text. Use "s1.equals(s2)" to see if two strings match instead.
- 05-13-2011, 06:08 PM #3
Member
- Join Date
- May 2011
- Posts
- 4
- Rep Power
- 0
- 05-13-2011, 06:23 PM #4
Similar Threads
-
How do you properly use break?
By louist in forum New To JavaReplies: 3Last Post: 03-08-2011, 02:58 AM -
Calling function in Javascript- from other function
By jdigger in forum New To JavaReplies: 1Last Post: 02-27-2011, 09:00 PM -
Why java cant do sum properly
By thetimwu in forum New To JavaReplies: 3Last Post: 05-26-2010, 07:40 AM -
Possible? Callback function passed as arguments to another function
By TreyAU21 in forum Advanced JavaReplies: 3Last Post: 12-04-2009, 03:08 PM -
how to pause and repaint in a loop, to draw a mathematical function.
By Abdelhamidem in forum AWT / SwingReplies: 3Last Post: 06-05-2008, 11:10 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks