Lesson 8 Iterative Constructs in Java
Lesson 8 Iterative Constructs in Java
IN JAVA
SCOPE OF THIS CHAPTER
• WHAT IS A LOOP
• TYPES OF LOOPING STATEMENTS
• JUMP
• ENTRY AND EXIT CONTROLLED LOOPS
• BREAK AND CONTINUE
• FINITE,INFINITE,DELAY LOOPS
• WHILE,FOR-WHILE-DO
• COUNTER VARIABLES
•A construct in which statements are repeatedly executed till
condition is satisfied is called LOOP
•The variable ‘n’ starts with 1 and result is displayed , then it
increases by 1 and if condition is true it moves back and
update value of n.
•It continues till condition is false
•LOOP is a repetitive structure in which statements are
repeated until the given condition is false
TO DISPLAY “WELCOME” 10 TIMES
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
System.out.println(“WELCOME”);
WHY DO WE USE ITERATIVE
STATEMENTS???
To perform a particular task
again and again till the condition
is satisfied.
COMPONENTS OF ITERATIVE
STATEMENTS
do
for while
while
FOR LOOP
EXAMPLE
BREAK VS CONTINUE INSIDE FOR LOOP
•
1.How can we use the continue statement in Java?
• This statement is used only within looping statements. When the
continue statement is encountered, then it skips the current iteration
and the next iteration starts.
2.How can we use the break statement in Java?
• As soon as, the break statement is encountered inside the loop, that
loop is immediately terminated without executing the remaining code
in the body of that loop, and the program control reaches to next
statement written after that loop.
TYPES OF LOOP
They are broadly categorized as entry controlled
and exit controlled loop
A while loop iterates through a set of statements till its
Boolean condition returns false. As long as the condition
given evaluates to true, the loop iterates.
The basic syntax of Java while loop is:
initialization;
while(boolean condition)
{
//statements;
step;
}
DO WHILE LOOP
Following is the syntax for a do...while loop −
initialization;
do
{
// Statements
Step;
}
while(Boolean_expression);
USE OF BREAK IN WHILE AND DO WHILE LOOP
H A N K Y OU !
T