Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2007, 10:41 PM
Member
 
Join Date: Jul 2007
Posts: 2
tkdvipers is on a distinguished road
terminating a while loop with a string
Hi

I am doing my nut and have come to the conclusion that you can't terminate a while loop using a String.

For example

while ( userInput != "end")
{
userInput = dialogbox("Please enter your choice")
}

Obviously the above code is just an example, however I am trying to get my code to put each input by the user into a set.

I can compile the code and get the input from the user but when I input the string I have defined to terminate the loop, it just adds the input to the set. Do I have to format the string in a certain way??

Thanks in advance to any help given.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-09-2007, 10:47 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
You question is not clear. You would better paste your actual code here and describe it there.

Based on what you said here, i think you are comparing the string wrongly. A string variable is an object and you can't compare it with equals operator. You need to use equals method of it. (e.g. if (myString.equal("another string")))
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-09-2007, 11:32 PM
Member
 
Join Date: Jul 2007
Posts: 2
tkdvipers is on a distinguished road
Apologies for my question not being clear.

Your answer helped a lot as I was trying to compare a user input from a request box to a string as you would with a primitive type, forgetting about strings being objects.

The fact that I want each input to go into a set is not the issue, the issue is getting the while loop to terminate when the user enters *.

JavaBean I am much obliged to you, many many thanks.

Last edited by tkdvipers : 07-09-2007 at 11:47 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 07-10-2007, 12:23 AM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
No problem. I am happy to be able to help.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
while loop michcio New To Java 5 01-27-2008 01:56 AM
Using java.util.Scanner to search for a String in a String Java Tip Java Tips 0 11-20-2007 05:59 PM
i need assistance with a string triggered loop please! Phobos0001 New To Java 9 11-14-2007 03:44 PM
I can't seem to pass the value of a string variable into a string array mathias Java Applets 1 08-03-2007 11:52 AM
A loop that doesn't loop MichYer New To Java 2 07-30-2007 09:44 AM


All times are GMT +3. The time now is 10:40 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org