• Post Reply Bookmark Topic Watch Topic
  • New Topic

try and catches with returns ending program..  RSS feed

 
Eric Giblock
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my program structure is like this:

try
{
for(....) // loop through an array of 7 numbers
{
while (....) // loop through a binary search calculation
{
if....
else if ....
else
{
print results...
return;
}
}
}
}



my problem is that the return; code ends the program, and never finished the "for" loop at the top of the program... is there a way to end the IF statement after it prints the results so that the "for" loop goes to the next number and runs through the "while" loop

thanks
 
M Beck
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you're looking for the "break" statement.
 
Eric Giblock
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
of course it was that simple.. what a brain fart...

thanks..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!