English

Write the syntax and purpose of the switch statement.

Advertisements

Question

Write the syntax and purpose of the switch statement.

Short/Brief Note
Advertisements

Solution

The syntax of the switch statement is:

switch(expression)
{
case constant 1:
statement(s);
break;
case constant 2:
statement(s);
break;
.
.
.
.
default:
statement(s);
}

Purpose of switch statement:

The switch statement is a multi-way branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.

shaalaa.com
Selection Statements
  Is there an error in this question or solution?
Chapter 10: Flow of Control - Evaluation - Section - C [Page 178]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 11 TN Board
Chapter 10 Flow of Control
Evaluation - Section - C | Q 4. | Page 178
Advertisements
Share
Notifications



      Forgot password?
Use app×