Switch statement: Difference between revisions

Content deleted Content added
Bcwilmot (talk | contribs)
Alternative uses: Additional language support
Line 62:
 
===C, C++, Java, php, ActionScript===
In [[C (programming language)|C]] and similarly-constructed languages, the lack of '''break''' keywords to cause fall through of program execution from one block to the next is used extensively. For example, if n=2, the fourth case statement will produce a match to the control variable. The next line outputs "n is an even number.". As an apparent bug, execution continues through the next 3 case statements and to the next line, which outputs "n is a prime number." which is a common error due to a missing '''break''' statement. The '''break''' line after a case block causes the switch statement to conclude. If the user types in more than one digit, the '''default''' block is executed, producing an error message by executing the '''defualtdefault''' code.
 
<source lang="c">