Liste des Groupes | Revenir à cl c |
bart <bc@freeuk.com> writes:Take these two loops:
[...]My experience of multi-level break is that there are two main use-cases:I would oppose a change to C that only applied to innermost and
>
* Used in the current loop only (not necessarily the innermost to an
observer). This is the most common
>
* Used to exit the outermost loop
>
So to support these, named or even numbered loops are not
necessary. (Eg. I use 'exit' or 'exit all'.)
outermost loops. For one thing, I'm not aware of any other language
that does this (except perhaps your unnamed one). For another,
it's easy enough to define a feature that handles any arbitrary
nesting levels, by applying names (labels) to loops.
Having named labels do have some advantages, such as being absoluteI'm not sure what you mean by "relative". Do you have an example?
while indices are relative. But sometimes you need an absolute
reference when refactoring and sometimes you want it relative.
If, say, I have a "break 2" statement (the Bourne shell uses that
syntax), and I wanted to refactor the code, I'll at least have
to pay very close attention to the number, and likely change it.
Is that what you mean by "relative"? If I have "break NAME", it's
more likely that I won't have to change it. (Disclaimer: I don't
think I've ever used the "break N" feature of the Bourne shell.)
If function-wide label scope is used, then my A and B labels need to be unique, so copying code around is harder. If loop scopes are private, then you can do this:If duplicating within the same function, then you also need to thinkThat's hardly the only case where duplicating code within a function
about scope rules for those named labels.
can cause conflicts.
A common proposal is to use existing labels, whose scope is already
well defined. Labels have *function scope*. You just have to make
sure that all labels within a function are unique.
Les messages affichés proviennent d'usenet.