SlideShare a Scribd company logo
   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++;
       }

More Related Content

What's hot

Chapter 5 java
Chapter 5 javaChapter 5 java
Chapter 5 java
Ahmad sohail Kakar
 
Mule esb object_to_json
Mule esb object_to_jsonMule esb object_to_json
Mule esb object_to_json
Davide Rapacciuolo
 
Loop
LoopLoop
PRESENTATION ON FOR LOOP
PRESENTATION  ON FOR LOOPPRESENTATION  ON FOR LOOP
PRESENTATION ON FOR LOOP
Farooq Joyia
 
Control structures
Control structuresControl structures
Control structures
ElakkiyaS11
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C language
ErumShammim
 
Doo while
Doo whileDoo while
Doo while
sidneyodingo
 
Loops
LoopsLoops
Break
BreakBreak
Java Week9(A) Notepad
Java Week9(A)   NotepadJava Week9(A)   Notepad
Java Week9(A) Notepad
Chaitanya Rajkumar Limmala
 
Loops
LoopsLoops
個人メモ用(Pythonのexceptionをfromでかく理由)
個人メモ用(Pythonのexceptionをfromでかく理由)個人メモ用(Pythonのexceptionをfromでかく理由)
個人メモ用(Pythonのexceptionをfromでかく理由)
KyutatsuNishiura
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
Rj Baculo
 
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
Krishna Raj
 
Clojure concurrency overview
Clojure concurrency overviewClojure concurrency overview
Clojure concurrency overview
Sergey Stupin
 
Looping and Switchcase BDCR
Looping and Switchcase BDCRLooping and Switchcase BDCR
Looping and Switchcase BDCR
beriver
 
Fine grain process control 2nd nov
Fine grain process control 2nd novFine grain process control 2nd nov
Fine grain process control 2nd nov
SurendraGangarapu1
 
Igdpd c21 loops
Igdpd c21 loopsIgdpd c21 loops
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol28
 

What's hot (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
 

Viewers also liked

Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
Audience feedback
Audience feedbackAudience feedback
Audience feedback
Sarah_Louise
 
А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!А где продажи? Заставьте нетворкинг работать на вас!
А где продажи? Заставьте нетворкинг работать на вас!
Вера Бойко
 
Narrative theorists
Narrative theoristsNarrative theorists
Narrative theorists
Sarah_Louise
 
thermal handheld imaging camera
thermal handheld imaging camerathermal handheld imaging camera
thermal handheld imaging camera
Sagi Tchaika
 
Original Photography PTSD Powerpoint
Original Photography PTSD PowerpointOriginal Photography PTSD Powerpoint
Original Photography PTSD Powerpoint
TeaganC
 
Plain white t's
Plain white t'sPlain white t's
Plain white t's
Sarah_Louise
 
Media21 Fall 2011 Bibliography
Media21 Fall 2011 BibliographyMedia21 Fall 2011 Bibliography
Media21 Fall 2011 Bibliography
TeaganC
 
если вы фрилансер то можете всё
если вы фрилансер то можете всёесли вы фрилансер то можете всё
если вы фрилансер то можете всё
Вера Бойко
 
Casting
CastingCasting
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
 
Food Pyramid
Food PyramidFood Pyramid
Food Pyramid
meifert
 
Control statements in Java
Control statements  in JavaControl statements  in Java
Control statements in Java
Jin Castor
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
Eduonix Learning Solutions
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
Vijay A Raj
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
คอม Edit
คอม Editคอม Edit
คอม Edit
sunaree
 

Viewers also liked (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
 

Similar to Control structures

Control statements
Control statementsControl statements
Control statements
Kanwalpreet Kaur
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
It Academy
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 
Loops in c
Loops in cLoops in c
Loops in c
RekhaBudhwar
 
C language 2
C language 2C language 2
C language 2
Arafat Bin Reza
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
Ahmad Idrees
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
bluejayjunior
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
SHRIRANG PINJARKAR
 
Control structures
Control structuresControl structures
Control structures
Isha Aggarwal
 
Loops In C++
Loops In C++Loops In C++
Loops In C++
Banasthali Vidyapith
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
aprilyyy
 
cpu.pdf
cpu.pdfcpu.pdf
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
Loop structures
Loop structuresLoop structures
Loop structures
tazeem sana
 
Programming loop
Programming loopProgramming loop
Programming loop
University of Potsdam
 
Loops and iteration.docx
Loops and iteration.docxLoops and iteration.docx
Loops and iteration.docx
NkurikiyimanaGodefre
 
Iteration
IterationIteration
Iteration
Liam Dunphy
 
web presentation 138.pptx
web presentation 138.pptxweb presentation 138.pptx
web presentation 138.pptx
AbhiYadav655132
 
5.pptx fundamental programing one branch
5.pptx fundamental programing one branch5.pptx fundamental programing one branch
5.pptx fundamental programing one branch
ssuserdde43b
 
07 flow control
07   flow control07   flow control
07 flow control
dhrubo kayal
 

Similar to 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
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
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
 

Recently uploaded

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 

Recently uploaded (20)

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 

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