• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Anyway to go to top of a loop in JAVA?

OneOfTheseDays

Diamond Member
I want my program to go back to the beginning of the loop if something happens, instead of going down and executing the rest of the instructions of the loop. How can i do this? THe "break" command will simply exit me from the loop, and using the "continue" command will just execute the rest of the code below.
 
Put the rest of the code in an "if" block. Here's some pseudo code:

while (bla bla bla)
{
..........
..........

if ( !condition) // if the condition is NOT met, execute the remaining code. If the condition IS met, then skip this code.
{
execute remaining code....
}
}
 
What do you mean "continue" will execute the rest of the code below? "continue" should do exactly what you're looking for.
 
I think you mean this:


outerloop:
for (....) {

innerloop:
while() {

innermostloop:
do {
...
if ()
break outerloop;
elseif () continue innerloop;

}while();


}

You can label any loop structure (for, while, do, ...), and within the scope of the loop you can make a call to break <label> or continue <label>.
 
Back
Top