SlideShare a Scribd company logo
Looping (or)
Iterative Statements
Dr. Kuppusamy .P
Associate Professor / SCOPE
Content
• while
• do… while
• For
• enhance for
• continue statements
Dr. Kuppusamy P
Iterative Statements
• Iterative Statements - one or set of statements executed
multiple times based on a condition.
• Three types of Iterative Statements in java
• while
• do… while
• for
• enhanced for
Dr. Kuppusamy P
while loop
Syntax:
while (condition)
{
Statements //Body of the loop
}
Dr. Kuppusamy P
while loop example
public class WhileExample
{
public static void main(String args[])
{
int i = 0;
while (i < 10)
{
System.out.println("i: “ +i);
i++;
}
}
}
Dr. Kuppusamy P
Do - while loop
Syntax:
do
{
Statements //Body of the loop
} while (condition) ;
Dr. Kuppusamy P
Do-while loop example
public class DoWhileExample
{
public static void main(String args[])
{
int i = 1;
do
{
System.out.println("i: “ +i);
i++;
} while (i < 10) ;
}
}
Dr. Kuppusamy P
for loop
Syntax:
for(initialization; condition; increment/decrement)
{
Statements //Body of the loop
}
Dr. Kuppusamy P
Repeat
Yes
No
Statements
Initialization;
Condition;
increment/decrement
for loop example
public class ForExample
{
public static void main(String args[])
{
for (int i=1; i<=5; i++ )
{
System.out.println("i: “ +i);
}
}
}
Dr. Kuppusamy P
Enhanced for loop
Syntax:
for(declaration : Expression)
{
Statements //Body of the loop
}
Dr. Kuppusamy P
Enhanced for loop example
public class EnhancedForExample
{
public static void main(String args[])
{
int [] numbers = {10, 20, 30, 40, 50};
for(int i : numbers ) // for(int i=0; i < numbers; length(); i++)
{
System.out.println("i: “ +i); // System.out.println( “i: “+numbers[i] );
}
}
}
Dr. Kuppusamy P
continue statement
• The continue statement skips the current iteration of a loop
• In while and do loops, continue causes the control to go directly to the test
condition and then continue the iteration process
• In case of for loop, the increment section of the loop is executed before the test
condition is evaluated.
public class ContinueExample
{
public static void main(String[] args)
{
int [] num = {10, 20, 30, 40, 50};
for(int i : num )
{
if( i == 3 )
continue;
}
System.out.println( "i: "+i );
}
Dr. Kuppusamy P
References
Dr. Kuppusamy P
Herbert Schildt, “Java: The Complete Reference”, McGraw-Hill Education, Tenth edition,
2017.

More Related Content

Similar to Java iterative statements (20)

PPTX
LOOPING STATEMENTS, JAVA,PROGRAMMING LOGIC
DiwakaranM3
 
PPTX
130707833146508191
Tanzeel Ahmad
 
PDF
Lo43
lksoo
 
PDF
09
liankei
 
PPTX
Pi j1.4 loops
mcollison
 
PDF
L8
lksoo
 
PPTX
DAY_1.2.pptx
ishasharma835109
 
PPTX
Chapter 5 java
Ahmad sohail Kakar
 
PPTX
for loop in java
Majid Ali
 
PPT
Java Programming: Loops
Karwan Mustafa Kareem
 
PDF
Java Repetiotion Statements
Huda Alameen
 
PDF
DSA 103 Object Oriented Programming :: Week 3
Ferdin Joe John Joseph PhD
 
PPTX
Looping statements
AbhishekMondal42
 
PPT
Looping statements in Java
Jin Castor
 
PPTX
Java loops for, while and do...while
Jayfee Ramos
 
PPT
M C6java6
mbruggen
 
PPSX
C lecture 3 control statements slideshare
Gagan Deep
 
PPTX
C Programming: Looping Statements in C Pgm
Navya Francis
 
PPTX
Lesson 6 Understanding Loops and Conditional Statements.pptx
KiRe6
 
DOCX
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
monicafrancis71118
 
LOOPING STATEMENTS, JAVA,PROGRAMMING LOGIC
DiwakaranM3
 
130707833146508191
Tanzeel Ahmad
 
Lo43
lksoo
 
Pi j1.4 loops
mcollison
 
L8
lksoo
 
DAY_1.2.pptx
ishasharma835109
 
Chapter 5 java
Ahmad sohail Kakar
 
for loop in java
Majid Ali
 
Java Programming: Loops
Karwan Mustafa Kareem
 
Java Repetiotion Statements
Huda Alameen
 
DSA 103 Object Oriented Programming :: Week 3
Ferdin Joe John Joseph PhD
 
Looping statements
AbhishekMondal42
 
Looping statements in Java
Jin Castor
 
Java loops for, while and do...while
Jayfee Ramos
 
M C6java6
mbruggen
 
C lecture 3 control statements slideshare
Gagan Deep
 
C Programming: Looping Statements in C Pgm
Navya Francis
 
Lesson 6 Understanding Loops and Conditional Statements.pptx
KiRe6
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
monicafrancis71118
 

More from Kuppusamy P (20)

PDF
Recurrent neural networks rnn
Kuppusamy P
 
PDF
Deep learning
Kuppusamy P
 
PDF
Image segmentation
Kuppusamy P
 
PDF
Image enhancement
Kuppusamy P
 
PDF
Feature detection and matching
Kuppusamy P
 
PDF
Image processing, Noise, Noise Removal filters
Kuppusamy P
 
PDF
Flowchart design for algorithms
Kuppusamy P
 
PDF
Algorithm basics
Kuppusamy P
 
PDF
Problem solving using Programming
Kuppusamy P
 
PDF
Parts of Computer, Hardware and Software
Kuppusamy P
 
PDF
Strings in java
Kuppusamy P
 
PDF
Java methods or Subroutines or Functions
Kuppusamy P
 
PDF
Java arrays
Kuppusamy P
 
PDF
Java conditional statements
Kuppusamy P
 
PDF
Java data types
Kuppusamy P
 
PDF
Java introduction
Kuppusamy P
 
PDF
Logistic regression in Machine Learning
Kuppusamy P
 
PDF
Anomaly detection (Unsupervised Learning) in Machine Learning
Kuppusamy P
 
PDF
Machine Learning Performance metrics for classification
Kuppusamy P
 
PDF
Machine learning Introduction
Kuppusamy P
 
Recurrent neural networks rnn
Kuppusamy P
 
Deep learning
Kuppusamy P
 
Image segmentation
Kuppusamy P
 
Image enhancement
Kuppusamy P
 
Feature detection and matching
Kuppusamy P
 
Image processing, Noise, Noise Removal filters
Kuppusamy P
 
Flowchart design for algorithms
Kuppusamy P
 
Algorithm basics
Kuppusamy P
 
Problem solving using Programming
Kuppusamy P
 
Parts of Computer, Hardware and Software
Kuppusamy P
 
Strings in java
Kuppusamy P
 
Java methods or Subroutines or Functions
Kuppusamy P
 
Java arrays
Kuppusamy P
 
Java conditional statements
Kuppusamy P
 
Java data types
Kuppusamy P
 
Java introduction
Kuppusamy P
 
Logistic regression in Machine Learning
Kuppusamy P
 
Anomaly detection (Unsupervised Learning) in Machine Learning
Kuppusamy P
 
Machine Learning Performance metrics for classification
Kuppusamy P
 
Machine learning Introduction
Kuppusamy P
 
Ad

Recently uploaded (20)

PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
infertility, types,causes, impact, and management
Ritu480198
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Introduction presentation of the patentbutler tool
MIPLM
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Horarios de distribución de agua en julio
pegazohn1978
 
Ad

Java iterative statements

  • 1. Looping (or) Iterative Statements Dr. Kuppusamy .P Associate Professor / SCOPE
  • 2. Content • while • do… while • For • enhance for • continue statements Dr. Kuppusamy P
  • 3. Iterative Statements • Iterative Statements - one or set of statements executed multiple times based on a condition. • Three types of Iterative Statements in java • while • do… while • for • enhanced for Dr. Kuppusamy P
  • 4. while loop Syntax: while (condition) { Statements //Body of the loop } Dr. Kuppusamy P
  • 5. while loop example public class WhileExample { public static void main(String args[]) { int i = 0; while (i < 10) { System.out.println("i: “ +i); i++; } } } Dr. Kuppusamy P
  • 6. Do - while loop Syntax: do { Statements //Body of the loop } while (condition) ; Dr. Kuppusamy P
  • 7. Do-while loop example public class DoWhileExample { public static void main(String args[]) { int i = 1; do { System.out.println("i: “ +i); i++; } while (i < 10) ; } } Dr. Kuppusamy P
  • 8. for loop Syntax: for(initialization; condition; increment/decrement) { Statements //Body of the loop } Dr. Kuppusamy P Repeat Yes No Statements Initialization; Condition; increment/decrement
  • 9. for loop example public class ForExample { public static void main(String args[]) { for (int i=1; i<=5; i++ ) { System.out.println("i: “ +i); } } } Dr. Kuppusamy P
  • 10. Enhanced for loop Syntax: for(declaration : Expression) { Statements //Body of the loop } Dr. Kuppusamy P
  • 11. Enhanced for loop example public class EnhancedForExample { public static void main(String args[]) { int [] numbers = {10, 20, 30, 40, 50}; for(int i : numbers ) // for(int i=0; i < numbers; length(); i++) { System.out.println("i: “ +i); // System.out.println( “i: “+numbers[i] ); } } } Dr. Kuppusamy P
  • 12. continue statement • The continue statement skips the current iteration of a loop • In while and do loops, continue causes the control to go directly to the test condition and then continue the iteration process • In case of for loop, the increment section of the loop is executed before the test condition is evaluated. public class ContinueExample { public static void main(String[] args) { int [] num = {10, 20, 30, 40, 50}; for(int i : num ) { if( i == 3 ) continue; } System.out.println( "i: "+i ); } Dr. Kuppusamy P
  • 13. References Dr. Kuppusamy P Herbert Schildt, “Java: The Complete Reference”, McGraw-Hill Education, Tenth edition, 2017.