8
In an example of loops in kotlin documentation, we have some codes with the following excerpt:
loop@ for (i in 1..100) {
for (j in 1..100) {
if (...) break@loop
}
}
From what I read in the documentation, it appears to be a Label and that they can be placed in any type of expression, according to the text:
Any Expression in Kotlin may be marked with a label. Labels have the form of an Identifier Followed by the @Sign, for example: abc@, Foobar@ are Valid Labels (see the Grammar). To label an Expression, we just put a label in front of it
But in no language that I programmed until today was there a need to do something similar in a piece of code referring to a repeating structure.
I don’t understand the function of this loop@
at the beginning and the @loop
in the case of the examples provided in the documentation (in particular for
of the example).
What is the purpose of these Labels in an expression?
Is it about GOTO? Or is it something just like
region...endregion
of the C#?Why at the beginning of the code the
@
is after the wordloop
and then it’s at the beginning?
someone with better English than mine could translate the excerpt of the documentation to be attached to the question?
– Wallace Maxters