Breaking out of a Loop

Reply

Join Date: Mar 2004
Posts: 6
Reputation: Lost Chyld is an unknown quantity at this point 
Solved Threads: 0
Lost Chyld Lost Chyld is offline Offline
Newbie Poster

Breaking out of a Loop

 
0
  #1
Feb 17th, 2005
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;
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Breaking out of a Loop

 
0
  #2
Feb 17th, 2005
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.

  1. for int(i=0; i<10; i++)
  2. {
  3. if (i=2)
  4. {
  5. i = 11;
  6. }
  7. }
or something like that;
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 6
Reputation: Lost Chyld is an unknown quantity at this point 
Solved Threads: 0
Lost Chyld Lost Chyld is offline Offline
Newbie Poster

Re: Breaking out of a Loop

 
0
  #3
Feb 17th, 2005
I figured it out. I was comparing strings wrong. Once I fixed that, it worked.

Thanks for the help.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Breaking out of a Loop

 
0
  #4
Feb 17th, 2005
Ok, that was my second guess...
You have to use equals() to compare strings like you were wanting.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC