SlideShare a Scribd company logo
1 of 9
Nested Loops
Nested Loops
 A nested loop is a loop inside the body of another loop
 Inner (inside), outer (outside) loops:
for row in range(1, 3, 1): //outer
for col in range(1, 3, 1)://inner
print(row * col)
 Inner loop goes through all repetitions for each repetition of
outer loop
 Inner loop repetitions complete sooner than outer loop
 Total number of repetitions for inner loop is product of number
of repetitions of the two loops.
 Can nest different styles of loops together
Nesting Loops
 Nested loops are necessary when a task is performs a repetitive
operation and that task itself must be repeated.
 for initialize in range(start, stop, update): while(condition):
for initialize in range(start, stop, update):
while(condition):
 Just like when we worked with nested conditionals
 if (condition):
if (condition):
 For example, a digital clock is a good example of needing to nest
for loops.
Digital Clock
 How can we use loops to simulate a digital clock?
 What would each loop be responsible for keeping track of?
 There would be 3 loops:
 One would track the hour
 One would track the minutes
 One would track the seconds
 NOT AN ANALOG CLOCK, why??????
 What would it look like?
Digital Clock
 First let’s begin by creating a loop to display the seconds up to
a minute.
 Can anyone describe that loop???
for sec in range(0, 60, 1):
print(format(sec, ‘>2’)
 Question: What is the initialization, test and update for the
previous for loop?
 Question: What would it look like if we printed to the left with
setw(2)?
Digital Clock
 Now let’s add minutes by nesting our previous loop:
for min in range(0, 60, 1):
for sec in range(0, 60, 1):
print(format(min, ‘>2’), ”:”, format(sec, ‘>2’)
Digital Clock
for hour in range(0, 12, 1):
for min in range(0, 60, 1):
for sec in range(0, 60, 1):
print(format(hour, ‘>2’), ”:”, format(min, ‘>2’), ”:”, format(sec, ‘>2’)
 Question: What if we wanted to add AM/PM
Digital Clock
Assign 0 to
hour
hour <
12
Assign 0 to
sec
Assign 0 to
min
True
False
min <
60
False
True
sec <
60
Fals
True Print clock
Infinite Loops
 Loops must contain a way to terminate otherwise the loop will
continue to repeat until the program is interrupted.
 Infinite loops usually occur when the programmer forgets to write
code inside the loop making the Boolean expression false.

More Related Content

Similar to Nested Loops

The Ring programming language version 1.10 book - Part 90 of 212
The Ring programming language version 1.10 book - Part 90 of 212The Ring programming language version 1.10 book - Part 90 of 212
The Ring programming language version 1.10 book - Part 90 of 212Mahmoud Samir Fayed
 
Time brings all things to pass
Time brings all things to passTime brings all things to pass
Time brings all things to passKamil Witecki
 
Introducing MERLIN_3.0.pptx
Introducing MERLIN_3.0.pptxIntroducing MERLIN_3.0.pptx
Introducing MERLIN_3.0.pptxssuser716de5
 
The Ring programming language version 1.8 book - Part 84 of 202
The Ring programming language version 1.8 book - Part 84 of 202The Ring programming language version 1.8 book - Part 84 of 202
The Ring programming language version 1.8 book - Part 84 of 202Mahmoud Samir Fayed
 
Becoming a better developer with EXPLAIN
Becoming a better developer with EXPLAINBecoming a better developer with EXPLAIN
Becoming a better developer with EXPLAINLouise Grandjonc
 
Generating Automated and Online Test Oracles for Simulink Models with Continu...
Generating Automated and Online Test Oracles for Simulink Models with Continu...Generating Automated and Online Test Oracles for Simulink Models with Continu...
Generating Automated and Online Test Oracles for Simulink Models with Continu...Lionel Briand
 
UNIT I- Session 3.pptx
UNIT I- Session 3.pptxUNIT I- Session 3.pptx
UNIT I- Session 3.pptxabcdefgh690537
 
class12_time.ppt
class12_time.pptclass12_time.ppt
class12_time.pptGauravWaila
 
Notes2
Notes2Notes2
Notes2hccit
 
vibration of machines and structures
vibration of machines and structuresvibration of machines and structures
vibration of machines and structuresAniruddhsinh Barad
 
Algorithm-RepetitionSentinellNestedLoop_Solution.pptx
Algorithm-RepetitionSentinellNestedLoop_Solution.pptxAlgorithm-RepetitionSentinellNestedLoop_Solution.pptx
Algorithm-RepetitionSentinellNestedLoop_Solution.pptxAliaaAqilah3
 
Introduction to writing algorithms
Introduction to writing algorithmsIntroduction to writing algorithms
Introduction to writing algorithms Krishna Chaytaniah
 
OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?ScyllaDB
 

Similar to Nested Loops (20)

Java Programming: Loops
Java Programming: LoopsJava Programming: Loops
Java Programming: Loops
 
The Ring programming language version 1.10 book - Part 90 of 212
The Ring programming language version 1.10 book - Part 90 of 212The Ring programming language version 1.10 book - Part 90 of 212
The Ring programming language version 1.10 book - Part 90 of 212
 
Common clock path pessimism removal
Common clock path pessimism removalCommon clock path pessimism removal
Common clock path pessimism removal
 
Time brings all things to pass
Time brings all things to passTime brings all things to pass
Time brings all things to pass
 
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
 
Introducing MERLIN_3.0.pptx
Introducing MERLIN_3.0.pptxIntroducing MERLIN_3.0.pptx
Introducing MERLIN_3.0.pptx
 
Storm
StormStorm
Storm
 
Note 0
Note 0Note 0
Note 0
 
The Ring programming language version 1.8 book - Part 84 of 202
The Ring programming language version 1.8 book - Part 84 of 202The Ring programming language version 1.8 book - Part 84 of 202
The Ring programming language version 1.8 book - Part 84 of 202
 
Becoming a better developer with EXPLAIN
Becoming a better developer with EXPLAINBecoming a better developer with EXPLAIN
Becoming a better developer with EXPLAIN
 
Generating Automated and Online Test Oracles for Simulink Models with Continu...
Generating Automated and Online Test Oracles for Simulink Models with Continu...Generating Automated and Online Test Oracles for Simulink Models with Continu...
Generating Automated and Online Test Oracles for Simulink Models with Continu...
 
UNIT I- Session 3.pptx
UNIT I- Session 3.pptxUNIT I- Session 3.pptx
UNIT I- Session 3.pptx
 
Bb2
Bb2Bb2
Bb2
 
class12_time.ppt
class12_time.pptclass12_time.ppt
class12_time.ppt
 
Notes2
Notes2Notes2
Notes2
 
vibration of machines and structures
vibration of machines and structuresvibration of machines and structures
vibration of machines and structures
 
Algorithm-RepetitionSentinellNestedLoop_Solution.pptx
Algorithm-RepetitionSentinellNestedLoop_Solution.pptxAlgorithm-RepetitionSentinellNestedLoop_Solution.pptx
Algorithm-RepetitionSentinellNestedLoop_Solution.pptx
 
Virtual post rig
Virtual post rigVirtual post rig
Virtual post rig
 
Introduction to writing algorithms
Introduction to writing algorithmsIntroduction to writing algorithms
Introduction to writing algorithms
 
OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?OSNoise Tracer: Who Is Stealing My CPU Time?
OSNoise Tracer: Who Is Stealing My CPU Time?
 

More from primeteacher32

More from 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
 
Conditional Loops
Conditional LoopsConditional Loops
Conditional Loops
 
Introduction to Repetition Structures
Introduction to Repetition StructuresIntroduction to Repetition Structures
Introduction to Repetition Structures
 
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
 

Recently uploaded

VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackSuhani Kapoor
 
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home MadeDubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Madekojalkojal131
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...shivangimorya083
 
Final Completion Certificate of Marketing Management Internship
Final Completion Certificate of Marketing Management InternshipFinal Completion Certificate of Marketing Management Internship
Final Completion Certificate of Marketing Management InternshipSoham Mondal
 
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service BhilaiVIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样umasea
 
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...Suhani Kapoor
 
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一A SSS
 
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一Fs
 
How to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdfHow to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdfmayank158542
 
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一lvtagr7
 
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一A SSS
 
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一F La
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of JobRemote DBA Services
 
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)obuhobo
 
Gray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdfGray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdfpadillaangelina0023
 
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdfobuhobo
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girlsshivangimorya083
 
VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...Suhani Kapoor
 

Recently uploaded (20)

VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service CuttackVIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
VIP Call Girl Cuttack Aashi 8250192130 Independent Escort Service Cuttack
 
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home MadeDubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
Dubai Call Girls Naija O525547819 Call Girls In Dubai Home Made
 
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
Delhi Call Girls Preet Vihar 9711199171 ☎✔👌✔ Whatsapp Body to body massage wi...
 
Final Completion Certificate of Marketing Management Internship
Final Completion Certificate of Marketing Management InternshipFinal Completion Certificate of Marketing Management Internship
Final Completion Certificate of Marketing Management Internship
 
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service BhilaiVIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
VIP Call Girl Bhilai Aashi 8250192130 Independent Escort Service Bhilai
 
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
办理学位证(纽伦堡大学文凭证书)纽伦堡大学毕业证成绩单原版一模一样
 
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
VIP Russian Call Girls in Bhilai Deepika 8250192130 Independent Escort Servic...
 
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
办理学位证(Massey证书)新西兰梅西大学毕业证成绩单原版一比一
 
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
定制(Waikato毕业证书)新西兰怀卡托大学毕业证成绩单原版一比一
 
How to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdfHow to Find the Best NEET Coaching in Indore (2).pdf
How to Find the Best NEET Coaching in Indore (2).pdf
 
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
定制(UQ毕业证书)澳洲昆士兰大学毕业证成绩单原版一比一
 
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
办理学位证(UoM证书)北安普顿大学毕业证成绩单原版一比一
 
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
办理(NUS毕业证书)新加坡国立大学毕业证成绩单原版一比一
 
do's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Jobdo's and don'ts in Telephone Interview of Job
do's and don'ts in Telephone Interview of Job
 
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
阿德莱德大学本科毕业证成绩单咨询(书英文硕士学位证)
 
Gray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdfGray Gold Clean CV Resume2024tod (1).pdf
Gray Gold Clean CV Resume2024tod (1).pdf
 
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCeCall Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
Call Girls In Prashant Vihar꧁❤ 🔝 9953056974🔝❤꧂ Escort ServiCe
 
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
加利福尼亚大学伯克利分校硕士毕业证成绩单(价格咨询)学位证书pdf
 
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call GirlsDelhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
Delhi Call Girls In Atta Market 9711199012 Book Your One night Stand Call Girls
 
VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...
VIP Call Girls Service Saharanpur Aishwarya 8250192130 Independent Escort Ser...
 

Nested Loops

  • 2. Nested Loops  A nested loop is a loop inside the body of another loop  Inner (inside), outer (outside) loops: for row in range(1, 3, 1): //outer for col in range(1, 3, 1)://inner print(row * col)  Inner loop goes through all repetitions for each repetition of outer loop  Inner loop repetitions complete sooner than outer loop  Total number of repetitions for inner loop is product of number of repetitions of the two loops.  Can nest different styles of loops together
  • 3. Nesting Loops  Nested loops are necessary when a task is performs a repetitive operation and that task itself must be repeated.  for initialize in range(start, stop, update): while(condition): for initialize in range(start, stop, update): while(condition):  Just like when we worked with nested conditionals  if (condition): if (condition):  For example, a digital clock is a good example of needing to nest for loops.
  • 4. Digital Clock  How can we use loops to simulate a digital clock?  What would each loop be responsible for keeping track of?  There would be 3 loops:  One would track the hour  One would track the minutes  One would track the seconds  NOT AN ANALOG CLOCK, why??????  What would it look like?
  • 5. Digital Clock  First let’s begin by creating a loop to display the seconds up to a minute.  Can anyone describe that loop??? for sec in range(0, 60, 1): print(format(sec, ‘>2’)  Question: What is the initialization, test and update for the previous for loop?  Question: What would it look like if we printed to the left with setw(2)?
  • 6. Digital Clock  Now let’s add minutes by nesting our previous loop: for min in range(0, 60, 1): for sec in range(0, 60, 1): print(format(min, ‘>2’), ”:”, format(sec, ‘>2’)
  • 7. Digital Clock for hour in range(0, 12, 1): for min in range(0, 60, 1): for sec in range(0, 60, 1): print(format(hour, ‘>2’), ”:”, format(min, ‘>2’), ”:”, format(sec, ‘>2’)  Question: What if we wanted to add AM/PM
  • 8. Digital Clock Assign 0 to hour hour < 12 Assign 0 to sec Assign 0 to min True False min < 60 False True sec < 60 Fals True Print clock
  • 9. Infinite Loops  Loops must contain a way to terminate otherwise the loop will continue to repeat until the program is interrupted.  Infinite loops usually occur when the programmer forgets to write code inside the loop making the Boolean expression false.