Java Reference
In-Depth Information
Multiple choice
switch
conditionals are often used by programmers for
displaying messages
2
:
Program 2.3
Demonstration of the
switch case
statement
int
dd=3;
// 0 for Monday, 6 for Sunday
switch
(dd)
case
0:
System . out . println (
"Monday"
);
break
;
case
1:
System . out . println (
"Tuesday"
);
break
;
case
2:
System . out . println (
"Wednesday"
);
break
;
case
3:
System . out . println (
"Thursday"
);
break
;
case
4:
System . out . println (
"Friday"
);
break
;
case
5:
System . out . println (
"Saturday"
);
break
;
case
6:
System . out . println (
"Sunday"
);
break
;
default
:
System . out . println (
"Out of scope!"
);
}
2.3 Blocks and scopes of variables
2.3.1 Blocks of instructions
A block of instructions is a set of instructions that is executed sequentially.
Blocks of instructions are delimited by braces, as shown below:
{
// This is a block
// (There are no control structures inside it)
Instruction1;
Instruction2;
...
}
A block is semantically interpreted as an atomic instruction at a macroscopic
level when parsing.
2
Or used for translating one type to another when used in functions
Search WWH ::
Custom Search