Skip to content

Files

Latest commit

 

History

History
53 lines (44 loc) · 803 Bytes

unnecessary_breaks.md

File metadata and controls

53 lines (44 loc) · 803 Bytes

Pattern: Unnecessary break

Issue: -

Description

Only use a break in a non-empty switch case statement if you need to break before the end of the case body. Dart does not support fallthrough execution for non-empty cases, so breaks at the end of non-empty switch case statements are unnecessary.

Example of incorrect code:

switch (1) {
 case 1:
  print("one");
  break;
 case 2:
  print("two");
  break;
}

Example of correct code:

switch (1) {
 case 1:
  print("one");
 case 2:
  print("two");
}
switch (1) {
 case 1:
 case 2:
  print("one or two");
}
switch (1) {
 case 1:
  break;
 case 2:
  print("just two");
}

Further Reading