944,028 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 11949
  • Java RSS
Feb 17th, 2005
0

Breaking out of a Loop

Expand Post »
I need help with breaking out of a loop. I know it's something simple, but I can't remember. Here's my code.

for(count = 0; count < inputArray.length; count++)
{
inputArray[count] = JOptionPane.showInputDialog(
null,
"Please input a name or exit: ",
"Input Name",
JOptionPane.QUESTION_MESSAGE);

if(inputArray[count] == "Exit")
{
break;
}
}
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Lost Chyld is offline Offline
6 posts
since Mar 2004
Feb 17th, 2005
0

Re: Breaking out of a Loop

I don't think you can use the break statement in for loops. I guess you would have to set the count variable to something greater than the ending condition in the loop, that way it won't loop anymore.

Java Syntax (Toggle Plain Text)
  1. for int(i=0; i<10; i++)
  2. {
  3. if (i=2)
  4. {
  5. i = 11;
  6. }
  7. }
or something like that;
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Feb 17th, 2005
0

Re: Breaking out of a Loop

I figured it out. I was comparing strings wrong. Once I fixed that, it worked.

Thanks for the help.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
Lost Chyld is offline Offline
6 posts
since Mar 2004
Feb 17th, 2005
0

Re: Breaking out of a Loop

Ok, that was my second guess...
You have to use equals() to compare strings like you were wanting.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Help! Scanning through each image pixel...
Next Thread in Java Forum Timeline: passing arrays to classes?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC