3 ms·
How is this any more readable than: for(Person p: persons) { if(p.getAge() >= 18) // lines of code here } If anything, I would argue t
by eeperson 15y ago
How is this any more readable than:
for(Person p: persons) {
if(p.getAge() >= 18)
// lines of code here
}
If anything, I would argue that this version is clearer since it makes the context of execution more explicit.
- z92 15y agoUnless you have multiple of these conditional checks when the indention level gets unholy. Continue in loop is like early return from a function. Some say we should not use it. But other find it really painful to work without 'continue'. I remember moving whole body of a loop into a function call only to get "continue" support in Lua though early return.
- eeperson 15y agoWhy would this cause indention level to get bad? Couldn't you simply chain these conditions in a single if statement?
- z92 15y agoNot if you need to pre calculate before some conditional checks, do something if some conditions are meet and you want to save state. Basically it all comes down to organizing code. Removing 'continue' removes one's ability to organize code in a good way, as some see it.