Technically, the switch statement is equivalent to the following if.else. In practice, you often use a switch statement to replace a complex if.else.if statement to make the code more readable. The following flowchart illustrates the switch statement: The switch statement is like the if…else…if statement. That the switch statement will stop comparing the expression‘s result with the remaining case values as long as it finds a match. If the result of the expression does not strictly equal to any value, the switch statement will execute the statement in the default branch. If you skip the break statement, the code execution falls through the original case branch into the next one. If you need to make a choice between more than one alternatives based on a given test condition, the switch statement can be used. The break statement exits the switch statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |