0% found this document useful (0 votes)
27 views8 pages

Lect8 Java

This document discusses different types of control statements in Java including selection statements (if-else), iteration statements (for, while, do-while loops), and jump statements (break, continue, return). Selection statements allow a program to choose between multiple paths using conditional logic. Iteration statements enable repeating blocks of code through loops. Jump statements change the normal sequential program flow, such as breaking out of a loop or returning from a method.

Uploaded by

Mahir Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
27 views8 pages

Lect8 Java

This document discusses different types of control statements in Java including selection statements (if-else), iteration statements (for, while, do-while loops), and jump statements (break, continue, return). Selection statements allow a program to choose between multiple paths using conditional logic. Iteration statements enable repeating blocks of code through loops. Jump statements change the normal sequential program flow, such as breaking out of a loop or returning from a method.

Uploaded by

Mahir Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

JAVA PROGRAMMING

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.

• Java’s program control statements can be put into the


following categories:
• Selection statements allow your program to choose different paths of
execution based upon the outcome of an expression or the state of a
variable.

• Iteration statements enable program execution to repeat one or more


statements (that is, iteration statements form loops).

• Jump statements allow your program to execute in a nonlinear


fashion
Selection Statements
• Also called as Decision making statements because it provides the
decision making capabilities to the statements.
• In selection statement, there are two types:
1. if statement
2. switch statement
• Diffent formats of if statement:
• Simple if
• Nested if
• If..else
• If..else if Ladder

• 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.

• “continue” keyword use for continuing the loop.

• Labelled block to jump at specific statement:


• We can give label to a block of statements with any valid name.
LOOP1: for(i=1;i<100;i++)
{
System.out.println(““);
for(j=1;j<100;j++)
{
System.out.println(“$ ”);
if(i==j)
{
continue LOOP1;
}
}
return statement
 The return statement causes program control to transfer back to
the caller of the method.

• At any time in a method the return statement can be used to cause


execution to branch back to the caller of the method.

• Thus, the return statement immediately terminates the method in


which it is executed.
class Return {
public static void main(String args[]) {
boolean t = true;
System.out.println("Before the return.");
if(t) return; // return to caller
System.out.println("This won't execute.");
}
}
The output from this program is shown here:
Before the return.

You might also like