Re: simplest problem ever
- From: JC <jonny.coombes@xxxxxxxxx>
- Date: Thu, 27 Apr 2006 10:43:57 +0100
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...
.
- Follow-Ups:
- Re: simplest problem ever
- From: Gordon Beaton
- Re: simplest problem ever
- References:
- simplest problem ever
- From: Christo
- Re: simplest problem ever
- From: Gordon Beaton
- Re: simplest problem ever
- From: Sigmund Hansen
- simplest problem ever
- Prev by Date: Re: Saving Serialized objects
- Next by Date: Re: simplest problem ever
- Previous by thread: Re: simplest problem ever
- Next by thread: Re: simplest problem ever
- Index(es):
Relevant Pages
|
|