Break and continue

Use break to stop looping:

1. while (true) {
2. if (shutDownRequested()) break;
3. processIncomingRequests();
4. }

Use continue to skip to the next loop iteration:

1. for (int i = 0; i < candidates.length; i++) {
2. var candidate = candidates[i];
3. if (candidate.yearsExperience < 5) {
4. continue;
5. }
6. candidate.interview();
7. }

You might write that example differently if you’re using anIterable such as a list or set:

1. candidates
2. .where((c) => c.yearsExperience >= 5)
3. .forEach((c) => c.interview());