5.7. Loop statements: break and continue

[5.5] Use break and continue

Imagine that you’ve defined a loop to iterate through a list of managers, and you’re looking for at least one manager whose name starts with the letter D. You’d like to exit the loop after you find the first match, but how? You can do this by using the break statement in your loop.

Now imagine that you want to iterate through all the folders on your laptop and scan any files larger than 10 MB for viruses. If all those files are found to be OK, you want to upload them to a server. But what if you’d like to skip the steps of virus checking and file uploading for file sizes less than 10 MB yet still proceed with the remaining files on your laptop? You can! ...

Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.