-
A break keyword only breaks out of its immediate scope. If you have a switch statement inside a for loop, a break in one of the switch statement’s case clauses breaks out of the case, not the for loop. Use a labeled break if you want to exit the for loop from a case.
-
Prefer a blank switch over a series of if and else blocks when the cases are related comparisons. The switch signals the relationship, aligns the conditions, and makes the default explicit.
-
Avoid fallthrough. While it can be helpful in rare cases, reconsider your implementation if you find yourself using it.
-
Use goto only when the alternatives, like Boolean flags or code duplication, make the code’s logic harder to understand.
Progress is saved on this device.