Lect8 Java
Lect8 Java
Code : 05201201
MCA [ Semester-I ]
Faculty of IT & Compute Science
PARUL UNIVERSITY
Code : 05201201
UNIT-1 Introduction to Java
[Datatypes, Operators, Statements]
Lecture – 8
• Control statements :
• Selection ,
• Iteration and
• Jumping Statements
CONTROL STATEMNTS
• A programming language uses control statements to cause
the flow of execution to advance and branch based on
changes to the state of a program.
• switch statement:
switch(condition)// condition means case value
{
case value-1:statement block1;break;
case value-2:statement block2;break;
…
default:statement block-default;break;
}
Cont..
• Nested switch Statements
switch(count)
{
case 1:
switch(target)
{ // nested switch
case 0:
System.out.println("target is zero");
break;
case 1: // no conflicts with outer switch
System.out.println("target is one");
break;
}
break;
case 2: // ...
Iteration Statements [looping]
• The process of repeatedly executing a statements and is called
as looping. The statements may be executed multiple times (from
zero to infinite number).
• Looping is also called as iterations.
• In Iteration statement, there are three types of operation:
• for loop
for(initialization;condition;iteration)
{
Statement block;
}
• while loop: while(condition){ Statement block;}
• do-while loop:
do
{
Statement block;
}
while(condition);
jumps in statement
• “break” keyword use for exiting from loop.