Java Learning Made Easy by Dheeraj Mehrotra - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Switch Statement

01906.jpg

It has the following format :

01907.jpg

switch(expression)

01908.jpg

{

01909.jpg

case value1:

01910.jpgblock1
01911.jpgbreak;
01912.jpgcase value2:
01913.jpg

block2

01914.jpg

break;

01915.jpg

———

01916.jpg

default:

01917.jpg

block

01918.jpg01919.jpg

break;

01920.jpg

} The break statement used at the end of each case acts as an exit point from the

01921.jpg01922.jpg

switch statement. It works as a jumping statement and the execution is transferred

01923.jpg

to the statement following the switch statement. The Default statement is the

01924.jpg

executing condition in the condition when the value of switch does not match with

01925.jpg

the case. It does not require any usage of break as it is always the last segment of
the switch structure.

01926.jpg01927.jpg01928.jpg01929.jpg01930.jpg01931.jpgattention@computerscienceexpertise.com
01932.jpg01933.jpg01934.jpg01935.jpg01936.jpg01937.jpg01938.jpg01939.jpg01940.jpg01941.jpg01942.jpg01943.jpg01944.jpg01945.jpg01946.jpg01947.jpg01948.jpg01949.jpg01950.jpg01951.jpg01952.jpg01953.jpg