language design - Why does Java allow for labeled breaks on arbitrary statements? -


i learned today following java code legal:

myblock: {     /* ... code ... */      if (doneexecutingthisblock())         break myblock;      /* ... more code ... */ } 

note myblock isn't loop - it's block of code i've delimited curly braces.

this seems rather strange feature have. means can use named break break out of if statement or anonymous block, though can't use break statement in these contexts.

my question this: is there reason design decision? is, why make can break out of enclosing statements using labeled breaks not regular breaks? , why allow behavior @ all? given how (comparatively) well-designed java language assume there's reason this, can't think of one.

it plausible done simplicity. if labeled break can break loop statements, should clear language designer restriction isn't necessary, semantics work same statements. economics of language spec, , simpler implementation of compilers, or out of habit towards generality, labeled break defined statement, not loop statements.

now can , judge choice. benefit programmers, giving them expression power? seems little, feature used. cost programmers in learning , understanding? seems so, evidenced discussion.

if go time , change it, you? can't would. have fetish generality.

if in parallel universe limited loop statements only, there still chance, smaller, posts question on stackoverflow: why couldn't work on arbitrary statements?


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -