SlideShare ist ein Scribd-Unternehmen logo
1 von 10
Downloaden Sie, um offline zu lesen
Conditional Loops Python
• An application sometimes needs to perform
repetitive actions like:
 Summing Numbers(Averages)
 Entering Multiple Data Entries
 Prompting the User Till the Correct Value is Entered
 A shopping list(scanning through the shopping list and
getting the items 1 by one until the list is down and
then you leave)
 
• When a program repeatedly runs a set of
statements it is referred to as a loop, iteration
or repetition structure.
• There are several types of looping structures:
 While Loops
 Do-While Loops
 For Loops
Counter Controlled Loops
Condional Loops
• Loops are similar to conditionals because they run
on a true/false value set. The loop continuously
runs while the condition is true and terminates
when it is false.
• Loops can be run for a desired length or until a
flag terminates them
 Great technique to reuse code and therefore limit
the amount of statements a program needs. Reusing
the same conditional arguments for testing instead
of posting hundreds.
True
False
 Question: How many statements are needed
for the following?
 Ask the same question 100 times
 Store the answer in a variable
 Check whether the answer is one of two answers
 Question: How many statements are needed if
we loop the code?
• A While Loop is a loop that executes 0 or more times
before terminating.
• Pre-conditional loop
 Code:
 Creating a While Loop:
 while (condition statement):
statement1
statement2
 
 Debugging Techniques:
 Setup a counter to keep track of the number of times a loop runs
 Set up a counter to count if an event is occurring or the number
of times it occurs
 Output values each time a loop executes
num = eval(input(“Enter a number less than 10:”))
while (number >= 10):
print(“Invalid Entry!”)
num = eval(input(“Enter a number less than 10:”))
 Counter: a variable that is incremented or
decremented each time a loop repeats
 Can be used to control execution of the loop
(also known as the loop control variable)
 Must be initialized before entering loop
Conditional Loops Python
Conditional Loops Python

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Java loops
Java loopsJava loops
Java loops
 
Loops in java script
Loops in java scriptLoops in java script
Loops in java script
 
Iteration
IterationIteration
Iteration
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
C++ loop
C++ loop C++ loop
C++ loop
 
Nested loops
Nested loopsNested loops
Nested loops
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Loop c++
Loop c++Loop c++
Loop c++
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Looping statement
Looping statementLooping statement
Looping statement
 
Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structure
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
Loops in c
Loops in cLoops in c
Loops in c
 
Loops c++
Loops c++Loops c++
Loops c++
 

Andere mochten auch

Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsP3 InfoTech Solutions Pvt. Ltd.
 
Year 7 lesson 5 if statements
Year 7 lesson 5   if statementsYear 7 lesson 5   if statements
Year 7 lesson 5 if statementstmoncrieff
 
Connect all your customers on one multichannel platform!
Connect all your customers on one multichannel platform!Connect all your customers on one multichannel platform!
Connect all your customers on one multichannel platform!Slawomir Kluczewski
 
Variables and Expressions
Variables and ExpressionsVariables and Expressions
Variables and Expressionsprimeteacher32
 
20 C programs
20 C programs20 C programs
20 C programsnavjoth
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry piSudar Muthu
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial javaTpoint s
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Pythondidip
 
Cloud Computing to Internet of Things
Cloud Computing to Internet of ThingsCloud Computing to Internet of Things
Cloud Computing to Internet of ThingsHermesDDS
 
Got Python I/O: IoT Develoment in Python via GPIO
Got Python I/O: IoT Develoment in Python via GPIOGot Python I/O: IoT Develoment in Python via GPIO
Got Python I/O: IoT Develoment in Python via GPIOAdam Englander
 
Internet of Things for Libraries
Internet of Things for LibrariesInternet of Things for Libraries
Internet of Things for LibrariesNicole Baratta
 
C programs
C programsC programs
C programsMinu S
 

Andere mochten auch (20)

Formatting Output
Formatting  OutputFormatting  Output
Formatting Output
 
Computer Logic
Computer LogicComputer Logic
Computer Logic
 
Functions
FunctionsFunctions
Functions
 
Function Returns
Function ReturnsFunction Returns
Function Returns
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
 
Year 7 lesson 5 if statements
Year 7 lesson 5   if statementsYear 7 lesson 5   if statements
Year 7 lesson 5 if statements
 
Connect all your customers on one multichannel platform!
Connect all your customers on one multichannel platform!Connect all your customers on one multichannel platform!
Connect all your customers on one multichannel platform!
 
Input
InputInput
Input
 
Logical Operators
Logical OperatorsLogical Operators
Logical Operators
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Variables and Expressions
Variables and ExpressionsVariables and Expressions
Variables and Expressions
 
20 C programs
20 C programs20 C programs
20 C programs
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry pi
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Socket Programming In Python
Socket Programming In PythonSocket Programming In Python
Socket Programming In Python
 
Cloud Computing to Internet of Things
Cloud Computing to Internet of ThingsCloud Computing to Internet of Things
Cloud Computing to Internet of Things
 
Got Python I/O: IoT Develoment in Python via GPIO
Got Python I/O: IoT Develoment in Python via GPIOGot Python I/O: IoT Develoment in Python via GPIO
Got Python I/O: IoT Develoment in Python via GPIO
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Internet of Things for Libraries
Internet of Things for LibrariesInternet of Things for Libraries
Internet of Things for Libraries
 
C programs
C programsC programs
C programs
 

Ähnlich wie Conditional Loops Python

Introduction to Repetition Structures
Introduction to Repetition StructuresIntroduction to Repetition Structures
Introduction to Repetition Structuresprimeteacher32
 
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
 
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...Daniel Katz
 
Switch statement in C.pptx
Switch statement in C.pptxSwitch statement in C.pptx
Switch statement in C.pptxMoinYaqoob
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxssusere336f4
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxAmy Nightingale
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJanCarlBriones2
 
Week04
Week04Week04
Week04hccit
 
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...Daniel Katz
 
Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Abou Bakr Ashraf
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 

Ähnlich wie Conditional Loops Python (20)

Introduction to Repetition Structures
Introduction to Repetition StructuresIntroduction to Repetition Structures
Introduction to Repetition Structures
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Conditional Loops
Conditional LoopsConditional Loops
Conditional Loops
 
Programming loop
Programming loopProgramming loop
Programming loop
 
Repitition Structure
Repitition StructureRepitition Structure
Repitition Structure
 
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
 
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 7, 8 - Pr...
 
Switch statement in C.pptx
Switch statement in C.pptxSwitch statement in C.pptx
Switch statement in C.pptx
 
Lesson 5
Lesson 5Lesson 5
Lesson 5
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
Going loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptxGoing loopy - Introduction to Loops.pptx
Going loopy - Introduction to Loops.pptx
 
JAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptxJAN CARL BRIONES-Writing Programs Using Loops.pptx
JAN CARL BRIONES-Writing Programs Using Loops.pptx
 
Week04
Week04Week04
Week04
 
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 6 - Profe...
 
Slide 6_Control Structures.pdf
Slide 6_Control Structures.pdfSlide 6_Control Structures.pdf
Slide 6_Control Structures.pdf
 
control structure
control structurecontrol structure
control structure
 
Loops
LoopsLoops
Loops
 
Visula C# Programming Lecture 4
Visula C# Programming Lecture 4Visula C# Programming Lecture 4
Visula C# Programming Lecture 4
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 

Mehr von primeteacher32

Mehr von primeteacher32 (20)

Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life Cycle
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
Returning Data
Returning DataReturning Data
Returning Data
 
Intro to Functions
Intro to FunctionsIntro to Functions
Intro to Functions
 
Introduction to GUIs with guizero
Introduction to GUIs with guizeroIntroduction to GUIs with guizero
Introduction to GUIs with guizero
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
Nested Loops
Nested LoopsNested Loops
Nested Loops
 
Input Validation
Input ValidationInput Validation
Input Validation
 
Windows File Systems
Windows File SystemsWindows File Systems
Windows File Systems
 
Nesting Conditionals
Nesting ConditionalsNesting Conditionals
Nesting Conditionals
 
Conditionals
ConditionalsConditionals
Conditionals
 
Intro to Python with GPIO
Intro to Python with GPIOIntro to Python with GPIO
Intro to Python with GPIO
 
Variables and Statements
Variables and StatementsVariables and Statements
Variables and Statements
 
Variables and User Input
Variables and User InputVariables and User Input
Variables and User Input
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Raspberry Pi
Raspberry PiRaspberry Pi
Raspberry Pi
 
Hardware vs. Software Presentations
Hardware vs. Software PresentationsHardware vs. Software Presentations
Hardware vs. Software Presentations
 
Block chain security
Block chain securityBlock chain security
Block chain security
 
Hashes
HashesHashes
Hashes
 
System Administration
System AdministrationSystem Administration
System Administration
 

Kürzlich hochgeladen

Moaaz Hassan El-Shayeb - Projects Portfolio
Moaaz Hassan El-Shayeb - Projects PortfolioMoaaz Hassan El-Shayeb - Projects Portfolio
Moaaz Hassan El-Shayeb - Projects Portfoliomoaaz el-shayeb
 
How to Host a Successful Webinar for Success?
How to Host a Successful Webinar for Success?How to Host a Successful Webinar for Success?
How to Host a Successful Webinar for Success?StrengthsTheatre
 
10 Things That Will Shape the Future of Education.pdf
10 Things That Will Shape the Future of Education.pdf10 Things That Will Shape the Future of Education.pdf
10 Things That Will Shape the Future of Education.pdfEducationView
 
asdfasdiofujasloidfoia nslkflsdkaf jljffs
asdfasdiofujasloidfoia nslkflsdkaf jljffsasdfasdiofujasloidfoia nslkflsdkaf jljffs
asdfasdiofujasloidfoia nslkflsdkaf jljffsJulia Kaye
 
reStartEvents March 28th TS/SCI & Above Employer Directory.pdf
reStartEvents March 28th TS/SCI & Above Employer Directory.pdfreStartEvents March 28th TS/SCI & Above Employer Directory.pdf
reStartEvents March 28th TS/SCI & Above Employer Directory.pdfKen Fuller
 
FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...
FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...
FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...FaHaD .H. NooR
 
ASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJF
ASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJFASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJF
ASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJFJulia Kaye
 
wealth_spend_bharatpeVerse_Analysis .pptx
wealth_spend_bharatpeVerse_Analysis .pptxwealth_spend_bharatpeVerse_Analysis .pptx
wealth_spend_bharatpeVerse_Analysis .pptxAnuragBhakuni4
 
Chapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, Conventions
Chapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, ConventionsChapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, Conventions
Chapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, ConventionsMd Shaifullar Rabbi
 
Blockchain_TezosDeveloperCommunitySNSCE.pdf
Blockchain_TezosDeveloperCommunitySNSCE.pdfBlockchain_TezosDeveloperCommunitySNSCE.pdf
Blockchain_TezosDeveloperCommunitySNSCE.pdfVISHNURAJSSNSCEAD
 
Nashon Holloway - Media/Press Kit - Priv
Nashon Holloway - Media/Press Kit - PrivNashon Holloway - Media/Press Kit - Priv
Nashon Holloway - Media/Press Kit - PrivNashonHolloway
 
Fireman Resume Strikuingly Text............................
Fireman Resume Strikuingly Text............................Fireman Resume Strikuingly Text............................
Fireman Resume Strikuingly Text............................calvinjamesmappala
 
kids gpaddfghtggvgghhhuuuuuhhhgggggy.pptx
kids gpaddfghtggvgghhhuuuuuhhhgggggy.pptxkids gpaddfghtggvgghhhuuuuuhhhgggggy.pptx
kids gpaddfghtggvgghhhuuuuuhhhgggggy.pptxJagrutiSononee
 
Audhina Nur Afifah Resume & Portofolio_2024.pdf
Audhina Nur Afifah Resume & Portofolio_2024.pdfAudhina Nur Afifah Resume & Portofolio_2024.pdf
Audhina Nur Afifah Resume & Portofolio_2024.pdfaudhinafh1
 
127. Reviewer Certificate in BP International
127. Reviewer Certificate in BP International127. Reviewer Certificate in BP International
127. Reviewer Certificate in BP InternationalManu Mitra
 
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...Chapter-4 Introduction to Global Distributions System and Computerized Reserv...
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...Md Shaifullar Rabbi
 
STORY OF SUSAN & JUDY - CEREBRAL PALSY.pptx
STORY OF SUSAN & JUDY - CEREBRAL PALSY.pptxSTORY OF SUSAN & JUDY - CEREBRAL PALSY.pptx
STORY OF SUSAN & JUDY - CEREBRAL PALSY.pptxsheenam bansal
 

Kürzlich hochgeladen (17)

Moaaz Hassan El-Shayeb - Projects Portfolio
Moaaz Hassan El-Shayeb - Projects PortfolioMoaaz Hassan El-Shayeb - Projects Portfolio
Moaaz Hassan El-Shayeb - Projects Portfolio
 
How to Host a Successful Webinar for Success?
How to Host a Successful Webinar for Success?How to Host a Successful Webinar for Success?
How to Host a Successful Webinar for Success?
 
10 Things That Will Shape the Future of Education.pdf
10 Things That Will Shape the Future of Education.pdf10 Things That Will Shape the Future of Education.pdf
10 Things That Will Shape the Future of Education.pdf
 
asdfasdiofujasloidfoia nslkflsdkaf jljffs
asdfasdiofujasloidfoia nslkflsdkaf jljffsasdfasdiofujasloidfoia nslkflsdkaf jljffs
asdfasdiofujasloidfoia nslkflsdkaf jljffs
 
reStartEvents March 28th TS/SCI & Above Employer Directory.pdf
reStartEvents March 28th TS/SCI & Above Employer Directory.pdfreStartEvents March 28th TS/SCI & Above Employer Directory.pdf
reStartEvents March 28th TS/SCI & Above Employer Directory.pdf
 
FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...
FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...
FAHAD HASSAN NOOR || UCP Business School Data Analytics Head Recommended | MB...
 
ASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJF
ASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJFASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJF
ASDFSDFASDFASDFASDFOUIASHDFOIASUD FOIJSADO;IFJOISADJF
 
wealth_spend_bharatpeVerse_Analysis .pptx
wealth_spend_bharatpeVerse_Analysis .pptxwealth_spend_bharatpeVerse_Analysis .pptx
wealth_spend_bharatpeVerse_Analysis .pptx
 
Chapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, Conventions
Chapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, ConventionsChapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, Conventions
Chapter-1 IATA, UFTAA, ICAO, FAA, CAA, ATAB, Conventions
 
Blockchain_TezosDeveloperCommunitySNSCE.pdf
Blockchain_TezosDeveloperCommunitySNSCE.pdfBlockchain_TezosDeveloperCommunitySNSCE.pdf
Blockchain_TezosDeveloperCommunitySNSCE.pdf
 
Nashon Holloway - Media/Press Kit - Priv
Nashon Holloway - Media/Press Kit - PrivNashon Holloway - Media/Press Kit - Priv
Nashon Holloway - Media/Press Kit - Priv
 
Fireman Resume Strikuingly Text............................
Fireman Resume Strikuingly Text............................Fireman Resume Strikuingly Text............................
Fireman Resume Strikuingly Text............................
 
kids gpaddfghtggvgghhhuuuuuhhhgggggy.pptx
kids gpaddfghtggvgghhhuuuuuhhhgggggy.pptxkids gpaddfghtggvgghhhuuuuuhhhgggggy.pptx
kids gpaddfghtggvgghhhuuuuuhhhgggggy.pptx
 
Audhina Nur Afifah Resume & Portofolio_2024.pdf
Audhina Nur Afifah Resume & Portofolio_2024.pdfAudhina Nur Afifah Resume & Portofolio_2024.pdf
Audhina Nur Afifah Resume & Portofolio_2024.pdf
 
127. Reviewer Certificate in BP International
127. Reviewer Certificate in BP International127. Reviewer Certificate in BP International
127. Reviewer Certificate in BP International
 
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...Chapter-4 Introduction to Global Distributions System and Computerized Reserv...
Chapter-4 Introduction to Global Distributions System and Computerized Reserv...
 
STORY OF SUSAN & JUDY - CEREBRAL PALSY.pptx
STORY OF SUSAN & JUDY - CEREBRAL PALSY.pptxSTORY OF SUSAN & JUDY - CEREBRAL PALSY.pptx
STORY OF SUSAN & JUDY - CEREBRAL PALSY.pptx
 

Conditional Loops Python

  • 2. • An application sometimes needs to perform repetitive actions like:  Summing Numbers(Averages)  Entering Multiple Data Entries  Prompting the User Till the Correct Value is Entered  A shopping list(scanning through the shopping list and getting the items 1 by one until the list is down and then you leave)  
  • 3. • When a program repeatedly runs a set of statements it is referred to as a loop, iteration or repetition structure. • There are several types of looping structures:  While Loops  Do-While Loops  For Loops Counter Controlled Loops Condional Loops
  • 4. • Loops are similar to conditionals because they run on a true/false value set. The loop continuously runs while the condition is true and terminates when it is false. • Loops can be run for a desired length or until a flag terminates them  Great technique to reuse code and therefore limit the amount of statements a program needs. Reusing the same conditional arguments for testing instead of posting hundreds. True False
  • 5.  Question: How many statements are needed for the following?  Ask the same question 100 times  Store the answer in a variable  Check whether the answer is one of two answers  Question: How many statements are needed if we loop the code?
  • 6. • A While Loop is a loop that executes 0 or more times before terminating. • Pre-conditional loop  Code:  Creating a While Loop:  while (condition statement): statement1 statement2    Debugging Techniques:  Setup a counter to keep track of the number of times a loop runs  Set up a counter to count if an event is occurring or the number of times it occurs  Output values each time a loop executes
  • 7. num = eval(input(“Enter a number less than 10:”)) while (number >= 10): print(“Invalid Entry!”) num = eval(input(“Enter a number less than 10:”))
  • 8.  Counter: a variable that is incremented or decremented each time a loop repeats  Can be used to control execution of the loop (also known as the loop control variable)  Must be initialized before entering loop