label_undefined
Can't reference an undefined label '{0}'.
Description
#The analyzer produces this diagnostic when it finds a reference to a label that isn't defined in the scope of the break
or continue
statement that is referencing it.
Example
#The following code produces this diagnostic because the label loop
isn't defined anywhere:
dart
void f() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j != 0) {
break loop;
}
}
}
}
Common fixes
#If the label should be on the innermost enclosing do
, for
, switch
, or while
statement, then remove the label:
dart
void f() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j != 0) {
break;
}
}
}
}
If the label should be on some other statement, then add the label:
dart
void f() {
loop: for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j != 0) {
break loop;
}
}
}
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.