Professional Documents
Culture Documents
CONDITIONAL Switch STATEMENT
CONDITIONAL Switch STATEMENT
Introduction
• switch statements which are used to perform
only specific block of statements in a program
called Case Control Statements.
• It tests the value of a variable and compares it
with multiple cases. Once the case match is
found, a block of statements associated with
that particular case is executed [1].
FORMAT: Flowchart of
switch STATEMENT switch STATEMENT
switch (variable)
{
case 1: statement; break;
case 2: statement; break;
case 3: statement; break;
.
.
case 4: statement; break;
default: statement;
}
FORMATS:
switch STATEMENT
switch (variable) switch (variable)
{ {
case ‘a’: statement; break; case ‘+’: statement; break;
case ‘b’: statement; break; case ‘-’: statement; break;
case ‘c’: statement; break; case ‘*’: statement; break;
. .
. .
case ‘z’: statement; break; case ‘%’: statement; break;
default: statement; default: statement;
} }
Break
• Terminates the loop immediately when
encountered.
Example 1:
• Write a C++ program CONDITIONAL switch
STATEMENT that determine if the first
inputted number is greater or lesser or equal
to the second inputted number.
Example 2:
• Write a C++ program CONDITIONAL switch
STATEMENT that determine operator [+,-,*,/]
to be applied in getting the result of two
inputted numbers.
References: