Image

Java, loops, and break (a simple but important question)

I'm a little unsure about using break in loops with java. I tried to look this up online, and based on that, here is what I think would happen in this code:


for ( i = 0; i < agentList.size(); i++ ) {
a = (Agent) agentList.get(i);
if ( a.getBirthDate() == getTickCount() )
break;
do other stuff A;
}

do other stuff B;


I think that if the if statement is true, and break is hit, then other stuff B gets done next. Is that right?

Is there something other than break that could send flow back up to the for loop rather than out of the for loop if the if statement is true? I know I could put the rest of the stuff in the for loop (do other stuff A) in an if statement so it gets done only if the existing if statement is not true. I just wonder if there are options here (and I want to clear up my break confusion once and for all).

Also, do you have a favorite online java resource to help answer questions like this?