In an example of loops in Kotlin documentation , we have some code with following excerpt:
loop@ for (i in 1..100) {
for (j in 1..100) {
if (...) break@loop
}
}
As I read in the documentation, it seems to be a Label and they can be placed in any type of expression, as 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 any language I've programmed to date, there was a need to do something similar in a code snippet about a repeat structure.
I did not understand the function of this loop@
at the beginning and the @loop
in case of the examples presented in the documentation (mainly that of% of example%).
-
What is the purpose of these labels in an expression?
-
Does it have to do with GOTO? Or is it just something like
for
of C #?