What is the switch statement, Programming Languages

Assignment Help:

What is the switch Statement?

This is a different form of the multi way decision that It is well structured, but can only be used in certain cases where:

1. Here, Only one variable is tested, all branches must depend on the value of that variable. The variable should be an integral type. (int, long, short or char).

2. Every possible value of the variable can control a single branc and a final, catch all, default branch may optionally be used to trap all unspecified cases.

The universal form of switch statement is

            switch(variable name)

            {

                        case constant 1            :           {

                                                                        block 1;

                                                                        break;

                                                            }         

 

                        case constant 2            :           {

                                                                        block 1;

                                                                        break;

                                                }

 

            .................

            .................

 

            default :                       {

                                                                        default block;

                                                                        break;

                                                            }

            }

The switch statement tests the value of a variable name against a list of  integer or character constants When a match is found the statements corresponding to that constant are executed and The switch differs from the if - else, as switch can only test for equality whereas if - else can do any type of relational & logical condition checking. Note that a body of the switch statement is a compound statement and the expression must evaluate to an integertype.

Once the expression is calculated, the control jumps to the appropriate case label and the statements corresponding to that case is executed until the break statement is reached and the break statement is used as an exit from the switch statement, otherwise the following case statements will get executed. If not any of the case matches, the control goes to the default statement and that particular statement gets executed.


Related Discussions:- What is the switch statement

Flowchart and Pseudocode using Control Breaks, Shemrock Inc. is a brake pad...

Shemrock Inc. is a brake pad manufacturing company. This company uses raw materials, such as carbon powder, iron, ash, and resin. It wants to develop an inventory management system

Discuss the php operators, Question 1 Explain the history of Internet ...

Question 1 Explain the history of Internet Question 2 What are the advantages of DHTML? Question 3 Explain the concept of DOM Question 4 How does AJAX work

Assembly Language, need a program of any multiplication algorithm implement...

need a program of any multiplication algorithm implemented in assembly language x86 without using mul command

We need help for build a price quote generator, We need help for build a Pr...

We need help for build a Price Quote Generator I am interested in two things (A) a web based system that will allow a user to enter the parameters of their contests (there are o

ATM, The ATM will simulate a real world automated teller machine that suppo...

The ATM will simulate a real world automated teller machine that supports safe access to accounts from multiple concurrent clients.

C# XNA Game Development, I need help for C# XNA 2Dimension Game Development...

I need help for C# XNA 2Dimension Game Development. I am gonna send the question and my solution(incomplete). I need you to complete it. Can you help me about that. I have 6-7 days

Type of linear programming - dea, Type of Linear Programming - DEA The ...

Type of Linear Programming - DEA The Express Dry Cleaners currently has four locations in the Chicago area and willing be opening the fifth in the very near future.  Mr. James,

Service oriented architectures in xml, question 1: In the opening lecture I...

question 1: In the opening lecture I spoke about general changes in business - flatter organizations, process orientation as opposed to functional silos, focus on supply chains, gr

Develop a diagram to model functionality, Develop (i) a context diagram, an...

Develop (i) a context diagram, and (ii) a use case diagram to model the following functionalities of an online brokerage house. eBroker is a discount online broker. An account h

A Simple Distributed Computing Platform , You are asked to develop a replic...

You are asked to develop a replicator (client) that distributes a large job over a number of computers (a server group) on a single switched LAN (our BU04 lab). In this assignment,

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd