In a conversation earlier this week I was discussing certain language features, and I realized I don't have a good word / phrase to describe a particular feature.
Some languages, such as PHP, have a language construct which allows break
and continue
statements to accept a numeric parameter indicating which block should be affected. For example:
for ($i = 0; $i < 10; $i++)
for ($j = 10; $j > 0; $j--)
if ($j == $i)
break 2;
echo $i;
Because break 2;
causes the outer loop to break, the output is 1
. If this were break 1;
or just break;
the output would be 10
.
C# does not have any such construct. The equivalent would something like this:
for (i = 0; i < 10; i++) {
bool broken = false;
for (j = 10; j > 0; j--) {
if (j == i) {
broken = true;
break;
}
}
if (broken)
break;
}
Console.WriteLine(i);
But of course, this could also be accomplished using a goto
.
So my question is, what do you call this? Is there a specific name for this "break n" construct? I'd like to be able to say "Language X has parametric break and continue statements", or something like that.