473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

simplest problem ever

while ((mFood != "Y") || (mFood != "N"))
{
mFood = User.inputString("ENTER Y for food or N for no food");
}

well i think the code should say what i want to do

when i uinput Y i want the loop to end, same if i input N

but the loop isnt ending

help
Apr 19 '06 #1
5 2737
On Wed, 19 Apr 2006 20:03:07 +0100, Christo wrote:
while ((mFood != "Y") || (mFood != "N"))
{
mFood = User.inputString("ENTER Y for food or N for no food");
}

well i think the code should say what i want to do

when i uinput Y i want the loop to end, same if i input N

but the loop isnt ending


There are two problems here:

- to compare Strings, use String.equals(), not ==.

- The loop condition says to continue as long as the input is unequal
to either "Y" or "N". Since this is true of *every* String, the loop
will never end. Change the condition to && (and) instead.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Apr 19 '06 #2
Gordon Beaton wrote:
On Wed, 19 Apr 2006 20:03:07 +0100, Christo wrote:
while ((mFood != "Y") || (mFood != "N"))
{
mFood = User.inputString("ENTER Y for food or N for no food");
}

well i think the code should say what i want to do

when i uinput Y i want the loop to end, same if i input N

but the loop isnt ending


There are two problems here:

- to compare Strings, use String.equals(), not ==.

- The loop condition says to continue as long as the input is unequal
to either "Y" or "N". Since this is true of *every* String, the loop
will never end. Change the condition to && (and) instead.

/gordon


You might also want to use equalsIgnoreCase instead of just equals,
but that depends on whether or not your inputString method returns only
uppercase strings, or differentiates between input strings.
Apr 21 '06 #3
JC
Sigmund Hansen wrote:
Gordon Beaton wrote:
On Wed, 19 Apr 2006 20:03:07 +0100, Christo wrote:
while ((mFood != "Y") || (mFood != "N"))
{
mFood = User.inputString("ENTER Y for food or N for no
food");
}

well i think the code should say what i want to do

when i uinput Y i want the loop to end, same if i input N

but the loop isnt ending


There are two problems here:

- to compare Strings, use String.equals(), not ==.

- The loop condition says to continue as long as the input is unequal
to either "Y" or "N". Since this is true of *every* String, the loop
will never end. Change the condition to && (and) instead.

/gordon


You might also want to use equalsIgnoreCase instead of just equals,
but that depends on whether or not your inputString method returns only
uppercase strings, or differentiates between input strings.


You might also want to actually change the value of mFood each pass
through the loop...
Apr 27 '06 #4
On Wed, 19 Apr 2006 20:03:07 +0100, Christo wrote:
while ((mFood != "Y") || (mFood != "N"))
{
mFood = User.inputString("ENTER Y for food or N for no
food");
}
On Thu, 27 Apr 2006 10:43:57 +0100, JC wrote: You might also want to actually change the value of mFood each pass
through the loop...


See that assignment statement?

Apparently User.inputString() takes a prompt, and returns the user's
input.

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
Apr 27 '06 #5
JC
Gordon Beaton wrote:
On Wed, 19 Apr 2006 20:03:07 +0100, Christo wrote:
while ((mFood != "Y") || (mFood != "N"))
{
mFood = User.inputString("ENTER Y for food or N for no
food");
}


On Thu, 27 Apr 2006 10:43:57 +0100, JC wrote:
You might also want to actually change the value of mFood each pass
through the loop...


See that assignment statement?

Apparently User.inputString() takes a prompt, and returns the user's
input.

/gordon


<grin>
Silly me - didn't clock that.
</grin>
Apr 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mimages | last post by:
What's the SIMPLEST way to sell on a site? I am looking into osCommerce, but the amount of setup and configuration is overwhelming. I just want to take an existing site, dedicate a cell or two in a...
5
by: dave | last post by:
How would I go about creating the simplest routine in VB 6.0 to have a user E-Mail me the application name, date installed and his/her E-Mail Address ?
1
by: zbcong | last post by:
hello there are two ListViews with the SAME coloumns within one winform,i want to move the data from one ListView into other one,what is the simplest method? thank you!!
354
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets...
6
by: MLH | last post by:
I want to be able to read the file size of my config.sys file or other file from withing Access Basic module. I'm sure its already been done. Don't wanna reinvent wheel or lug nuts, etc.
4
by: Alan Silver | last post by:
Hello, I have a site that stores some info in an XML file. The file is pretty simple, of the form... <Site> <SiteName>Fred's Ferrets</SiteName> <SomeVar>Whatever</SomeVar> .... etc ......
3
by: | last post by:
For a given web form, I want to know what the +simplest+ way to add an attribute to all of a particular control type on that page. For example, I might want to add an onClick attribute to all...
82
by: Eric Lindsay | last post by:
I have been trying to get a better understanding of simple HTML, but I am finding conflicting information is very common. Not only that, even in what seemed elementary and without any possibility...
1
by: giannis | last post by:
I want when i click on a button "fill" a DataGridView with data from a "SELECT" SQL clause. What the simplest way to achieve this work with the use of the available bindingSource (without make...
0
by: Rico | last post by:
The simplest php webapp ever http://morecute.com
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.