aspose file tools
The moose likes Beginning Java and the fly likes Loops and the Continue Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Loops and the Continue Statement" Watch "Loops and the Continue Statement" New topic
Author

Loops and the Continue Statement

Landon Blake
Ranch Hand

Joined: Dec 04, 2003
Posts: 121
I want to have a loop that adds a value to a group of variables in sequential order. However, I want it to skip some of the variables if a tested condition is true, and the resume where it left off. Can you do this with a 'break' statement and a 'continue' statement, or does the continue statement alway return the loop to where it started? (If I use a for loop with a counter variable, when I break the loop and then continue it, will it resume with the last value of the counter varaible.)
I hope this question makes some sense.
Thanks for any help.
The Sunburned Surveyor
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
A "continue" will keep you in the innermost loop and put you back at the top. A "break" will cause you to exit from the innermost loop. It sounds like you want to use "continue". However you might be able to accomplish the same thing by using an "if" statement. We'd need more details to determine what is the 'best' way of doing it.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
continue will continue the loop at the next iteration.
This is a pretty simple thing to practice with and discover.
The odd numbers are printed. If continue didn't continue at the next iteration, we'd have an infinite loop.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Loops and the Continue Statement
 
Similar Threads
wield labeled continue statement
clarification: break and continue
break statement.
for loop
initialization in for()'s