Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

C++ Language/ProgramFlow/BreakStatement/FallthroughInSwitch

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

A switch statement is an efficient substitute for many if (x==1) {body} else if (x==5) {body} else if (x==99) {body} chains. In a switch statement, each body is a sequence of statements preceded by a case 5: label. If you don't terminate that sequence of statements by break;, then program flow will fall-through and also perform the next sequence of statements. This is often a programming bug, so when you intentionally do this, write [[fallthrough]]; in place of break;. Additional information about fallthrough (includes interactive examples)