Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

Switch Statements..........!

12 like 0 dislike
Hello every body,

                        I am interested to know about the forms of Switch statments...................
asked 1 year ago by biswaskeran (70,430 points)

2 Answers

4 like 0 dislike
Hi,

A switch statement should have the following form:

    switch (condition) {
    case ABC:
        statements;
        /* falls through */

    case DEF:
        statements;
        break;

    case XYZ:
        statements;
        break;

    default:
        statements;
        break;
    }

Every time a case falls through (doesn't include a break statement), add a comment where the break statement would normally be. This is shown in the preceding code example with the /* falls through */ comment.

Every switch statement should include a default case. The break in the default case is redundant, but it prevents a fall-through error if later another case is added.
answered 1 year ago by allian (14,180 points)
0 like 0 dislike
In computer programming, a switch statement is a type of selection control statement that exists in most modern imperative programming languages (e.g., Pascal, C, C++, C#, and Java). Its purpose is to allow the value of a variable or expression to control the flow of program execution via a multiway branch (or "goto", one of several labels). The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and (if the heuristics  permit), offering the potential of faster execution through compiler optimization. In some programming languages, a statement that is syntactically different but conceptually the same as the switch statement is known as a case statement, select statement or inspect instruction.
answered 1 year ago by marck_don (191,010 points)

Related questions

11 like 0 dislike
1 answer
12 like 0 dislike
1 answer
11 like 0 dislike
1 answer
9 like 0 dislike
1 answer
asked 1 year ago by lily (17,510 points)
10 like 0 dislike
1 answer
asked 1 year ago by biswaskeran (70,430 points)