break from if
Posted: Wed Jan 29, 2014 10:00 pm
Sometimes I wish there would be a 'break from if' statement.
the same idea of what you have with branches, only arbitrary predicate.
for example if you have some code after the "if-else ladder", or you just prefer one return statement for the whole function, but you don't want your code to go deep in ifs.
one option is to use early return, and keep shallow "if ... return, if ... return", taking into account that subsequent ifs are already elses to the first, since it has a return statement there.
I think an additional construct that jumps to the result could make code more readable. (kind of like what is done with require and ensure, pre and post code)
I know this is a somewhat exotic feature request.
what do you think?
examples can follow if you desire. (I have a real one too)
the same idea of what you have with branches, only arbitrary predicate.
for example if you have some code after the "if-else ladder", or you just prefer one return statement for the whole function, but you don't want your code to go deep in ifs.
one option is to use early return, and keep shallow "if ... return, if ... return", taking into account that subsequent ifs are already elses to the first, since it has a return statement there.
I think an additional construct that jumps to the result could make code more readable. (kind of like what is done with require and ensure, pre and post code)
I know this is a somewhat exotic feature request.
what do you think?
examples can follow if you desire. (I have a real one too)