Case Traversal Policy

From webCoRE Wiki - Web-enabled Community's own Rule Engine
Jump to: navigation, search
Share on FacebookShare on TwitterShare on Google+Share on LinkedInShare on DiggShare on deliciousShare on redditShare on StumbleUpon

A switch statement is an easy way to execute different things for different values of an operand. It does so by using cases, each with its own collection of statements to execute if matched. Typically, we only want one case to execute, then expect the switch statement to terminate and execution be handed over to the next statement, if any. This is the default behavior, also known as Safe, where the first and only the first matching case is executed.

The fall-through method allows cases to share statements. The switch statement will find the first matching case and execute its statements, then continues, or falls through with the next case, regardless of it matching or not, and then the next case, and so on, until the last case is executed, or until a break statement is reached. In this scenario, you need to manually add break statements to each case that needs to terminate the switch statement.