4 ms·
Another simple way to reduce nesting is to use "continue" rather than wrapping entire loops in if statements. For instance, this: for (file in files) {
by danvk 15y ago
Another simple way to reduce nesting is to use "continue" rather than wrapping entire loops in if statements.
For instance, this:
for (file in files) {
if (isOK(file)) {
... // nested two levels
}
}
becomes:
for (file in files) {
if (!isOK(file)) continue;
... // nested only one level
}
- aaronblohowiak 15y agoi vacillate between using continue/return to skip code and using indentation. It is shorter, but I find that it is not as skim-able -- (all?) other control flow is hinted at by indentation, but continue/break/return is not.
- obtu 15y agoreturn/continue/break really jump out with keyword highlighting.