SlideShare a Scribd company logo
1 of 20
Looping Statements
By : Abhishek Mondal
Repetition Statements
• Repetition statements allow us to execute a statement multiple
times
• Often they are referred to as loops
• Like conditional statements, they are controlled by boolean
expressions
• Java has three kinds of repetition statements:
– the while loop
– the do loop
– the for loop
The while Statement
• A while statement has the following syntax:
while ( condition ){statement; }
• If the condition is true, the statement is executed
• Then the condition is evaluated again, and if it is still true, the statement is executed again
• The statement is executed repeatedly until the condition becomes false
Logic of a while Loop
statement
true false
condition
evaluated
The while Statement
• An example of a while statement:
int count = 1; while (count <= 5){
System.out.println (count);
count++; }
• If the condition of a while loop is false initially, the statement is never executed
• Therefore, the body of a while loop will execute zero or more times
The while Statement
• Let's look at some examples of loop processing
• A loop can be used to maintain a running sum
• A sentinel value is a special input value that represents the end of input
• A loop can also be used for input validation, making a program more
robust
Infinite Loops
• The body of a while loop eventually must make the condition false
• If not, it is called an infinite loop, which will execute until the user interrupts the
program
• This is a common logical (semantic) error
• You should always double check the logic of a program to ensure that your
loops will terminate normally
Infinite Loops
• An example of an infinite loop:
int count = 1;
while (count <= 25){
System.out.println (count);
count = count - 1; }
• This loop will continue executing until interrupted (Control-C) or until an underflow error occurs
Nested Loops
• Similar to nested if statements, loops can be nested as well
• That is, the body of a loop can contain another loop
• For each iteration of the outer loop, the inner loop iterates completely
• Your second course project involves a while loop nested inside of a for loop
Nested Loops
• How many times will the string "Here" be printed?
count1 = 1; while (count1 <= 10){
count2 = 1;
while (count2 <= 20) {
System.out.println ("Here");
count2++;
} count1++;
}
10 * 20 = 200
The do-while Statement
• A do-while statement (also called a do loop) has the following syntax:
do{statement; }while ( condition )
• The statement is executed once initially, and then the condition is
evaluated
• The statement is executed repeatedly until the condition becomes false
Logic of a do-while Loop
condition
evaluated
statement
false
The do Statement
• An example of a do loop:
int count = 0;
do{ count++;
System.out.println (count);
} while (count < 5);
+The body of a do loop executes at least once
The for Statement
• A for statement has the following syntax:
+ The initialization The statement is is executed once
executed until the
+before the loop begins condition becomes false
+for ( initialization ; condition ; increment ){
+ statement;
+}
+The increment portion is executed at the end of
each
+iteration
Logic of a for loop
statement
true
condition
evaluated
false
increment
initialization
The for Statement
• A for loop is functionally equivalent to the following while
loop structure:
+initialization; while (
condition ){
statement; increment;
+}
The for Statement
• An example of a for loop:
+for (int count=1; count <= 5; count++){
+ System.out.println (count);
+}
• The initialization section can be used to declare a variable
• Like a while loop, the condition of a for loop is tested prior to
executing the loop body
The for Statement
• Therefore, the body of a for loop will execute zero or more
times
• The increment section can perform any
+ calculationfor (int num=100; num > 0; num -= 5){
System.out.println (num);
+}
• A for loop is well suited for executing statements a specific
number of times that can be calculated
The for Statement
• Each expression in the header of a for loop is optional
• If the initialization is left out, no initialization is performed
• If the condition is left out, it is always considered to be true,
and therefore creates an infinite loop
+– We usually call this a “forever loop”
• If the increment is left out, no increment operation is performed
Thank You

More Related Content

What's hot

PRESENTATION ON FOR LOOP
PRESENTATION  ON FOR LOOPPRESENTATION  ON FOR LOOP
PRESENTATION ON FOR LOOPFarooq Joyia
 
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...imtiazalijoono
 
Semaphores and Monitors
 Semaphores and Monitors Semaphores and Monitors
Semaphores and Monitorssathish sak
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#Binu Bhasuran
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Mindfire Solutions
 
Function procedure c6 c7
Function procedure  c6 c7Function procedure  c6 c7
Function procedure c6 c7Omar Al-Sabek
 
Communicating with Channels
Communicating with ChannelsCommunicating with Channels
Communicating with Channelsjlongster2
 
Flink Forward SF 2017: Konstantinos Kloudas - Extending Flink’s Streaming APIs
Flink Forward SF 2017: Konstantinos Kloudas -  Extending Flink’s Streaming APIsFlink Forward SF 2017: Konstantinos Kloudas -  Extending Flink’s Streaming APIs
Flink Forward SF 2017: Konstantinos Kloudas - Extending Flink’s Streaming APIsFlink Forward
 
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...Flink Forward
 
Workshop 05 Review
Workshop 05 ReviewWorkshop 05 Review
Workshop 05 Reviewmigiwara
 
Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...
Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...
Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...Flink Forward
 
Effective java item 80 and 81
Effective java   item 80 and 81Effective java   item 80 and 81
Effective java item 80 and 81Isaac Liao
 

What's hot (20)

Loops
LoopsLoops
Loops
 
PRESENTATION ON FOR LOOP
PRESENTATION  ON FOR LOOPPRESENTATION  ON FOR LOOP
PRESENTATION ON FOR LOOP
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
 
Semaphores and Monitors
 Semaphores and Monitors Semaphores and Monitors
Semaphores and Monitors
 
Apache flink 1.0.0 overview
Apache flink 1.0.0 overviewApache flink 1.0.0 overview
Apache flink 1.0.0 overview
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Fpga 12-event-control
Fpga 12-event-controlFpga 12-event-control
Fpga 12-event-control
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#Asynchronous programming in .net 4.5 with c#
Asynchronous programming in .net 4.5 with c#
 
Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1Asynchronous Programming in C# - Part 1
Asynchronous Programming in C# - Part 1
 
Introduction to VB.NET - UP SITF
Introduction to VB.NET - UP SITFIntroduction to VB.NET - UP SITF
Introduction to VB.NET - UP SITF
 
Function procedure c6 c7
Function procedure  c6 c7Function procedure  c6 c7
Function procedure c6 c7
 
Communicating with Channels
Communicating with ChannelsCommunicating with Channels
Communicating with Channels
 
Flink Forward SF 2017: Konstantinos Kloudas - Extending Flink’s Streaming APIs
Flink Forward SF 2017: Konstantinos Kloudas -  Extending Flink’s Streaming APIsFlink Forward SF 2017: Konstantinos Kloudas -  Extending Flink’s Streaming APIs
Flink Forward SF 2017: Konstantinos Kloudas - Extending Flink’s Streaming APIs
 
While loop
While loopWhile loop
While loop
 
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
Fabian Hueske_Till Rohrmann - Declarative stream processing with StreamSQL an...
 
Workshop 05 Review
Workshop 05 ReviewWorkshop 05 Review
Workshop 05 Review
 
Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...
Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...
Flink Forward Berlin 2017: Matt Zimmer - Custom, Complex Windows at Scale Usi...
 
Effective java item 80 and 81
Effective java   item 80 and 81Effective java   item 80 and 81
Effective java item 80 and 81
 

Similar to Looping statements

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in JavaJin Castor
 
Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesJason J Pulikkottil
 
Week04
Week04Week04
Week04hccit
 
3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdf3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdfsantosh147365
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in CSowmya Jyothi
 
While loop
While loopWhile loop
While loopFeras_83
 
whileloop-161225171903.pdf
whileloop-161225171903.pdfwhileloop-161225171903.pdf
whileloop-161225171903.pdfBasirKhan21
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxAmy Nightingale
 
Conditional Loops Python
Conditional Loops PythonConditional Loops Python
Conditional Loops Pythonprimeteacher32
 
Step Count Method for Time Complexity Analysis.pptx
Step Count Method for Time Complexity Analysis.pptxStep Count Method for Time Complexity Analysis.pptx
Step Count Method for Time Complexity Analysis.pptxvijaykumarsoni16
 

Similar to Looping statements (20)

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
15-Loops.ppt
15-Loops.ppt15-Loops.ppt
15-Loops.ppt
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
Repetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniquesRepetition, Basic loop structures, Loop programming techniques
Repetition, Basic loop structures, Loop programming techniques
 
Ch4_part1.ppt
Ch4_part1.pptCh4_part1.ppt
Ch4_part1.ppt
 
Ch4_part1.ppt
Ch4_part1.pptCh4_part1.ppt
Ch4_part1.ppt
 
Loops in c ii
Loops in c iiLoops in c ii
Loops in c ii
 
Week04
Week04Week04
Week04
 
Loops c++
Loops c++Loops c++
Loops c++
 
3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdf3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdf
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
Conditional Loops
Conditional LoopsConditional Loops
Conditional Loops
 
While loop
While loopWhile loop
While loop
 
whileloop-161225171903.pdf
whileloop-161225171903.pdfwhileloop-161225171903.pdf
whileloop-161225171903.pdf
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptx
 
Lesson 5
Lesson 5Lesson 5
Lesson 5
 
Control structure
Control structureControl structure
Control structure
 
Conditional Loops Python
Conditional Loops PythonConditional Loops Python
Conditional Loops Python
 
Step Count Method for Time Complexity Analysis.pptx
Step Count Method for Time Complexity Analysis.pptxStep Count Method for Time Complexity Analysis.pptx
Step Count Method for Time Complexity Analysis.pptx
 

More from AbhishekMondal42

Oss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantagesOss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantagesAbhishekMondal42
 
Word press posts(preview &amp; publish)
Word press posts(preview &amp; publish)Word press posts(preview &amp; publish)
Word press posts(preview &amp; publish)AbhishekMondal42
 
Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)AbhishekMondal42
 
Word press pages(edit and delete)
Word press pages(edit and delete)Word press pages(edit and delete)
Word press pages(edit and delete)AbhishekMondal42
 
Word press media(add,insert,delete)
Word press media(add,insert,delete)Word press media(add,insert,delete)
Word press media(add,insert,delete)AbhishekMondal42
 
Word press widget management
Word press  widget managementWord press  widget management
Word press widget managementAbhishekMondal42
 
Word press theme management
Word press  theme managementWord press  theme management
Word press theme managementAbhishekMondal42
 
Word press personal profile
Word press  personal profileWord press  personal profile
Word press personal profileAbhishekMondal42
 
Word press moderate comments
Word press  moderate commentsWord press  moderate comments
Word press moderate commentsAbhishekMondal42
 
Word press install plugins
Word press  install pluginsWord press  install plugins
Word press install pluginsAbhishekMondal42
 

More from AbhishekMondal42 (20)

Oss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantagesOss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantages
 
Word press 01
Word press 01Word press 01
Word press 01
 
Word press posts(preview &amp; publish)
Word press posts(preview &amp; publish)Word press posts(preview &amp; publish)
Word press posts(preview &amp; publish)
 
Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)
 
Word press pages(edit and delete)
Word press pages(edit and delete)Word press pages(edit and delete)
Word press pages(edit and delete)
 
Word press pages(add)
Word press pages(add)Word press pages(add)
Word press pages(add)
 
Word press media(add,insert,delete)
Word press media(add,insert,delete)Word press media(add,insert,delete)
Word press media(add,insert,delete)
 
Word press media library
Word press media libraryWord press media library
Word press media library
 
Word press widget management
Word press  widget managementWord press  widget management
Word press widget management
 
Word press view plugins
Word press  view pluginsWord press  view plugins
Word press view plugins
 
Word press user roles
Word press  user rolesWord press  user roles
Word press user roles
 
Word press theme management
Word press  theme managementWord press  theme management
Word press theme management
 
Word press personal profile
Word press  personal profileWord press  personal profile
Word press personal profile
 
Word press moderate comments
Word press  moderate commentsWord press  moderate comments
Word press moderate comments
 
Word press install plugins
Word press  install pluginsWord press  install plugins
Word press install plugins
 
Word press edit users
Word press  edit usersWord press  edit users
Word press edit users
 
Word press edit tags
Word press  edit tagsWord press  edit tags
Word press edit tags
 
Word press edit links
Word press  edit linksWord press  edit links
Word press edit links
 
Word press edit comments
Word press  edit commentsWord press  edit comments
Word press edit comments
 
Word press delete users
Word press  delete usersWord press  delete users
Word press delete users
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 

Looping statements

  • 1. Looping Statements By : Abhishek Mondal
  • 2. Repetition Statements • Repetition statements allow us to execute a statement multiple times • Often they are referred to as loops • Like conditional statements, they are controlled by boolean expressions • Java has three kinds of repetition statements: – the while loop – the do loop – the for loop
  • 3. The while Statement • A while statement has the following syntax: while ( condition ){statement; } • If the condition is true, the statement is executed • Then the condition is evaluated again, and if it is still true, the statement is executed again • The statement is executed repeatedly until the condition becomes false
  • 4. Logic of a while Loop statement true false condition evaluated
  • 5. The while Statement • An example of a while statement: int count = 1; while (count <= 5){ System.out.println (count); count++; } • If the condition of a while loop is false initially, the statement is never executed • Therefore, the body of a while loop will execute zero or more times
  • 6. The while Statement • Let's look at some examples of loop processing • A loop can be used to maintain a running sum • A sentinel value is a special input value that represents the end of input • A loop can also be used for input validation, making a program more robust
  • 7. Infinite Loops • The body of a while loop eventually must make the condition false • If not, it is called an infinite loop, which will execute until the user interrupts the program • This is a common logical (semantic) error • You should always double check the logic of a program to ensure that your loops will terminate normally
  • 8. Infinite Loops • An example of an infinite loop: int count = 1; while (count <= 25){ System.out.println (count); count = count - 1; } • This loop will continue executing until interrupted (Control-C) or until an underflow error occurs
  • 9. Nested Loops • Similar to nested if statements, loops can be nested as well • That is, the body of a loop can contain another loop • For each iteration of the outer loop, the inner loop iterates completely • Your second course project involves a while loop nested inside of a for loop
  • 10. Nested Loops • How many times will the string "Here" be printed? count1 = 1; while (count1 <= 10){ count2 = 1; while (count2 <= 20) { System.out.println ("Here"); count2++; } count1++; } 10 * 20 = 200
  • 11. The do-while Statement • A do-while statement (also called a do loop) has the following syntax: do{statement; }while ( condition ) • The statement is executed once initially, and then the condition is evaluated • The statement is executed repeatedly until the condition becomes false
  • 12. Logic of a do-while Loop condition evaluated statement false
  • 13. The do Statement • An example of a do loop: int count = 0; do{ count++; System.out.println (count); } while (count < 5); +The body of a do loop executes at least once
  • 14. The for Statement • A for statement has the following syntax: + The initialization The statement is is executed once executed until the +before the loop begins condition becomes false +for ( initialization ; condition ; increment ){ + statement; +} +The increment portion is executed at the end of each +iteration
  • 15. Logic of a for loop statement true condition evaluated false increment initialization
  • 16. The for Statement • A for loop is functionally equivalent to the following while loop structure: +initialization; while ( condition ){ statement; increment; +}
  • 17. The for Statement • An example of a for loop: +for (int count=1; count <= 5; count++){ + System.out.println (count); +} • The initialization section can be used to declare a variable • Like a while loop, the condition of a for loop is tested prior to executing the loop body
  • 18. The for Statement • Therefore, the body of a for loop will execute zero or more times • The increment section can perform any + calculationfor (int num=100; num > 0; num -= 5){ System.out.println (num); +} • A for loop is well suited for executing statements a specific number of times that can be calculated
  • 19. The for Statement • Each expression in the header of a for loop is optional • If the initialization is left out, no initialization is performed • If the condition is left out, it is always considered to be true, and therefore creates an infinite loop +– We usually call this a “forever loop” • If the increment is left out, no increment operation is performed