![]() In many languages, only the matching block is executed, and then execution continues at the end of the switch statement. This distinction is referred to as the treatment of fallthrough, which is elaborated below. The second form are unstructured switches, as in C, where the cases are treated as labels within a single block, and the switch functions as a generalized goto. This functions as a generalized if–then–else conditional, here with any number of branches, not just two. The first form are structured switches, as in Pascal, where exactly one branch is taken, and the cases are treated as separate, exclusive blocks. ![]() Semantically, there are two main forms of switch statements. In others, like PL/I, an error is raised. In some languages, such as C, if no case matches and the default is omitted the switch statement simply exits. This executes when none of the other cases match the control expression. In many languages, every case must also be preceded by a keyword such as case or when.Īn optional default case is typically also allowed, specified by a default, otherwise, or else keyword. The value (or list/range of values) is usually separated from the corresponding statement sequence by a colon or by an implication arrow.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |