Page 25 - Dart Language
P. 25
One surprising aspect of switch in Dart is that non-empty case clauses must end with break, or
less commonly, continue, throw, or return. That is, non-empty case clauses cannot fall through.
You must explicitly end a non-empty case clause, usually with a break. You will get a static
warning if you omit break, continue, throw, or return, and the code will error at that location at
runtime.
var command = 'OPEN';
switch (command) {
case 'OPEN':
executeOpen();
// ERROR: Missing break causes an exception to be thrown!!
case 'CLOSED': // Empty case falls through
case 'LOCKED':
executeClosed();
break;
}
If you want fall-through in a non-empty case, you can use continue and a label:
var command = 'OPEN';
switch (command) {
case 'OPEN':
executeOpen();
continue locked;
locked: case 'LOCKED':
executeClosed();
break;
}
Read Control Flow online: https://riptutorial.com/dart/topic/923/control-flow
https://riptutorial.com/ 20

