??? 05/30/12 04:04 Read: times |
#187579 - Switch Break. Responding to: ???'s previous message |
Justin Fontes said:
Why was the switch introduced if no example can be provided to be used within this context, other than to have completeness? Just another form of short-circuit evaluation, right? If one makes reference to where break can be used then it is certainly in the sense of completeness to mention the usage in the switch statement as well as in the various looping structures. Switch defines a block of code that has multiple entry points. Entry point selection is based upon the switch variable value. Once the execution path has vectored to one of the labeled entry points (the case statement locations) the code execution flow will proceed in a normal manner to the end of the code block. At any point one can introduce a break that causes the execution flow to stop in the block and proceed to the point past the end of the code block. If one wants each entry point to be its own set of code then there would be a break in the block at the end of each case section of of the code block. (There may very well be cases where this is not strictly true if the case block ends with some type of loop or iteration statement. In this case the break for that may need to be located inside the iterative structure. Breaks also play an part in early exit from a case block. In this latter situation the break may be part of a conditional statement. Michael Karas tructure. |