SlideShare ist ein Scribd-Unternehmen logo
1 von 11
   Repetition control structures
    ◦ are Java statements that allows us to execute
      specific blocks of code a number of times.

   Types:
    ◦ while-loop
    ◦ do-while loop
    ◦ for-loop
   while loop
    ◦ is a statement or block of statements that is repeated as
      long as some condition is satisfied.

   while loop has the form:
     while( boolean_expression ){
           statement1;
           statement2;
           . . .
     }

    ◦ The statements inside the while loop are executed as
      long as the boolean_expression evaluates to true.
int x = 0;

while (x<10) {
     System.out.println(x);
   x++;
}
//infinite loop
while(true)
     System.out.println(“hello”);
//no loops
// statement is not even executed
while (false)
     System.out.println(“hello”);
   do-while loop
    ◦ is similar to the while-loop
    ◦ statements inside a do-while loop are executed several times
      as long as the condition is satisfied
    ◦ The main difference between a while and do-while loop:
       the statements inside a do-while loop are executed at least
         once.

   do-while loop has the form:
      do{
          statement1;
          statement2;
          . . .
      }while( boolean_expression );
int x = 0;

do  {
     System.out.println(x);
     x++;
}while (x<10);
//infinite loop
do{
     System.out.println(“hello”);
} while (true);
//one loop
// statement is executed once
do
     System.out.println(“hello”);
while (false);
   for loop
    ◦ allows execution of the same code a number of times.

   for loop has the form:
    for(InitializationExpression;LoopCondition;StepExpres
    sion)
    {
       statement1;
       statement2;
       . . .
    }
    ◦ where,
       InitializationExpression -initializes the loop variable.
       LoopCondition - compares the loop variable to some limit
         value.
       StepExpression - updates the loop variable.
int i;
        for( i = 0; i < 10; i++ ){
             System.out.println(i);
        }
   The code shown above is equivalent to the
    following while loop.
       int i = 0;
       while( i < 10 ){
            System.out.print(i);
            i++;
       }

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (19)

Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
 
Mule esb object_to_json
Mule esb object_to_jsonMule esb object_to_json
Mule esb object_to_json
 
Loop
LoopLoop
Loop
 
PRESENTATION ON FOR LOOP
PRESENTATION  ON FOR LOOPPRESENTATION  ON FOR LOOP
PRESENTATION ON FOR LOOP
 
Control structures
Control structuresControl structures
Control structures
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C language
 
Doo while
Doo whileDoo while
Doo while
 
Loops
LoopsLoops
Loops
 
Break
BreakBreak
Break
 
Java Week9(A) Notepad
Java Week9(A)   NotepadJava Week9(A)   Notepad
Java Week9(A) Notepad
 
Loops
LoopsLoops
Loops
 
個人メモ用(Pythonのexceptionをfromでかく理由)
個人メモ用(Pythonのexceptionをfromでかく理由)個人メモ用(Pythonのexceptionをfromでかく理由)
個人メモ用(Pythonのexceptionをfromでかく理由)
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
 
Clojure concurrency overview
Clojure concurrency overviewClojure concurrency overview
Clojure concurrency overview
 
Looping and Switchcase BDCR
Looping and Switchcase BDCRLooping and Switchcase BDCR
Looping and Switchcase BDCR
 
Fine grain process control 2nd nov
Fine grain process control 2nd novFine grain process control 2nd nov
Fine grain process control 2nd nov
 
Igdpd c21 loops
Igdpd c21 loopsIgdpd c21 loops
Igdpd c21 loops
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 

Andere mochten auch

А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!
Вера Бойко
 
Narrative theorists
Narrative theoristsNarrative theorists
Narrative theorists
Sarah_Louise
 
Original Photography PTSD Powerpoint
Original Photography PTSD PowerpointOriginal Photography PTSD Powerpoint
Original Photography PTSD Powerpoint
TeaganC
 
Media21 Fall 2011 Bibliography
Media21 Fall 2011 BibliographyMedia21 Fall 2011 Bibliography
Media21 Fall 2011 Bibliography
TeaganC
 
если вы фрилансер то можете всё
если вы фрилансер то можете всёесли вы фрилансер то можете всё
если вы фрилансер то можете всё
Вера Бойко
 
Teagan C - Summative Reflections
Teagan C - Summative ReflectionsTeagan C - Summative Reflections
Teagan C - Summative Reflections
TeaganC
 
Summative Learning Reflection
Summative Learning ReflectionSummative Learning Reflection
Summative Learning Reflection
TeaganC
 
PTSD Rehabilitation Proposal
PTSD Rehabilitation ProposalPTSD Rehabilitation Proposal
PTSD Rehabilitation Proposal
TeaganC
 
Shaping Sheet
Shaping SheetShaping Sheet
Shaping Sheet
TeaganC
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
Jin Castor
 
คอม Edit
คอม Editคอม Edit
คอม Edit
sunaree
 

Andere mochten auch (20)

Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Audience feedback
Audience feedbackAudience feedback
Audience feedback
 
А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!
 
Narrative theorists
Narrative theoristsNarrative theorists
Narrative theorists
 
thermal handheld imaging camera
thermal handheld imaging camerathermal handheld imaging camera
thermal handheld imaging camera
 
Original Photography PTSD Powerpoint
Original Photography PTSD PowerpointOriginal Photography PTSD Powerpoint
Original Photography PTSD Powerpoint
 
Plain white t's
Plain white t'sPlain white t's
Plain white t's
 
Media21 Fall 2011 Bibliography
Media21 Fall 2011 BibliographyMedia21 Fall 2011 Bibliography
Media21 Fall 2011 Bibliography
 
если вы фрилансер то можете всё
если вы фрилансер то можете всёесли вы фрилансер то можете всё
если вы фрилансер то можете всё
 
Casting
CastingCasting
Casting
 
Teagan C - Summative Reflections
Teagan C - Summative ReflectionsTeagan C - Summative Reflections
Teagan C - Summative Reflections
 
Summative Learning Reflection
Summative Learning ReflectionSummative Learning Reflection
Summative Learning Reflection
 
PTSD Rehabilitation Proposal
PTSD Rehabilitation ProposalPTSD Rehabilitation Proposal
PTSD Rehabilitation Proposal
 
Shaping Sheet
Shaping SheetShaping Sheet
Shaping Sheet
 
Food Pyramid
Food PyramidFood Pyramid
Food Pyramid
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
คอม Edit
คอม Editคอม Edit
คอม Edit
 

Ähnlich wie Control structures

FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
bluejayjunior
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
aprilyyy
 

Ähnlich wie Control structures (20)

Control statements
Control statementsControl statements
Control statements
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Loops in c
Loops in cLoops in c
Loops in c
 
C language 2
C language 2C language 2
C language 2
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Control structures
Control structuresControl structures
Control structures
 
Loops In C++
Loops In C++Loops In C++
Loops In C++
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
Loop structures
Loop structuresLoop structures
Loop structures
 
Programming loop
Programming loopProgramming loop
Programming loop
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
 
Iteration
IterationIteration
Iteration
 
web presentation 138.pptx
web presentation 138.pptxweb presentation 138.pptx
web presentation 138.pptx
 
5.pptx fundamental programing one branch
5.pptx fundamental programing one branch5.pptx fundamental programing one branch
5.pptx fundamental programing one branch
 
07 flow control
07   flow control07   flow control
07 flow control
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Control structures

  • 1. Repetition control structures ◦ are Java statements that allows us to execute specific blocks of code a number of times.  Types: ◦ while-loop ◦ do-while loop ◦ for-loop
  • 2. while loop ◦ is a statement or block of statements that is repeated as long as some condition is satisfied.  while loop has the form: while( boolean_expression ){ statement1; statement2; . . . } ◦ The statements inside the while loop are executed as long as the boolean_expression evaluates to true.
  • 3. int x = 0; while (x<10) { System.out.println(x); x++; }
  • 4. //infinite loop while(true) System.out.println(“hello”);
  • 5. //no loops // statement is not even executed while (false) System.out.println(“hello”);
  • 6. do-while loop ◦ is similar to the while-loop ◦ statements inside a do-while loop are executed several times as long as the condition is satisfied ◦ The main difference between a while and do-while loop:  the statements inside a do-while loop are executed at least once.  do-while loop has the form: do{ statement1; statement2; . . . }while( boolean_expression );
  • 7. int x = 0; do { System.out.println(x); x++; }while (x<10);
  • 8. //infinite loop do{ System.out.println(“hello”); } while (true);
  • 9. //one loop // statement is executed once do System.out.println(“hello”); while (false);
  • 10. for loop ◦ allows execution of the same code a number of times.  for loop has the form: for(InitializationExpression;LoopCondition;StepExpres sion) { statement1; statement2; . . . } ◦ where,  InitializationExpression -initializes the loop variable.  LoopCondition - compares the loop variable to some limit value.  StepExpression - updates the loop variable.
  • 11. int i; for( i = 0; i < 10; i++ ){ System.out.println(i); }  The code shown above is equivalent to the following while loop. int i = 0; while( i < 10 ){ System.out.print(i); i++; }