SlideShare uma empresa Scribd logo
1 de 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++;
       }

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!
Вера Бойко
 
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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
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
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

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++; }