Java: break, continue, return in Loops

Although this is pretty basic Java functionality I often have to look this up, because I confound these calls, esp. break and continue. So this is my cheat sheet:

Break

for (..) {
  ..
  // leave loop immediately
  break;
  ..
}

Continue

for (..) {
  ..
  // continue loop with next iteration
  continue;
  ..
}

Return

for (..) {
  ..
  // leave calling method
  return;
  ..
}

Advertisement