SlideShare a Scribd company logo
1 of 10
JavaScript
Iterations
Charles Russell
Bennu Bird Media
Changes in Direction
●
In the previous video we allowed our program to
change flow to one of many different program
blocks
●
But that is not the only direction change we may
want. It is often desireable to repeatedly execute
the same block
●
Looking for some value in a list
●
Sending a group email
●
In other words we want to loop
The While loop
●
At the top of the loop the condition is checked
●
If the condition is met then execute code block
●
Loop will continue until condition not met.
while (conditional expression) {
//Do some stuff
}
●
Be sure that eventually the condition will not be
met otherwise you get an infinite loop;
The Do loop
●
At the bottom of the loop condition is checked
●
Assures the code block will be executed at least
once
●
Loop continues until condition false
do {
//code to execute goes here
} while (conditional expression);
Basic For loop
●
Executes the loop a number of times
●
Has three statements
●
First excutes before the loop is executed
– Usually used for initialization
●
Second conditional expression
– Code executes if true
●
Third
– Executes after the code block before the next
iteration
Basic For Syntax
for (init ; conditional exp; prepForNext) {
//do some stuff
}
For looping through
properties
●
Used to examine properties of an object
●
Important to filter as all properties examined
even those inherited from parent and its
parent....
for (variable in Object) {
if ( Object.hasOwnProperty(variable) {
//code to execute
}
}
Cutting the loop
●
break
●
Halts code execution in the loop
– Stop further execution of code block and exit the
loop
●
continue
●
Halts execution of the rest of the code block
●
Continues next iteration
Summary
●
Iteration is another word for looping
●
While loops check for conditional at the top of
the loop
●
Be wary of the infinite loop
●
Do loops check conditional at bottom of the loop
●
Basic for loops allow loops to be controlled by
number of executions
●
For in loops will check properties of Objects and
Arrays
●
Be sure to use hasOwnProperty method.
Next: Live Code

More Related Content

What's hot

Presenter kn
Presenter knPresenter kn
Presenter knogomr
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptTO THE NEW | Technology
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 
A tale of two(many) proxies
A tale of two(many) proxiesA tale of two(many) proxies
A tale of two(many) proxiesMohan Dutt
 
Modern Programming Languages - An overview
Modern Programming Languages - An overviewModern Programming Languages - An overview
Modern Programming Languages - An overviewAyman Mahfouz
 
Exploring reactive programming with Java
Exploring reactive programming with JavaExploring reactive programming with Java
Exploring reactive programming with JavaMiro Cupak
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGlobalLogic Ukraine
 
Loop control structure
Loop control structureLoop control structure
Loop control structurenarmadhakin
 
Best practices for unit testing RxJava
Best practices for unit testing RxJavaBest practices for unit testing RxJava
Best practices for unit testing RxJavaSimon Percic
 
Practical introduction to the actor model
Practical introduction to the actor modelPractical introduction to the actor model
Practical introduction to the actor modelGeorgios Gousios
 
Reactive programming in Java
Reactive programming in JavaReactive programming in Java
Reactive programming in JavaMiro Cupak
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion StatementsHuda Alameen
 
Dangers of parallel streams
Dangers of parallel streamsDangers of parallel streams
Dangers of parallel streamsLukáš Křečan
 

What's hot (20)

Presenter kn
Presenter knPresenter kn
Presenter kn
 
An introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScriptAn introduction to Object Oriented JavaScript
An introduction to Object Oriented JavaScript
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
JAVA Threads explained
JAVA Threads explained JAVA Threads explained
JAVA Threads explained
 
A tale of two(many) proxies
A tale of two(many) proxiesA tale of two(many) proxies
A tale of two(many) proxies
 
Modern Programming Languages - An overview
Modern Programming Languages - An overviewModern Programming Languages - An overview
Modern Programming Languages - An overview
 
Exploring reactive programming with Java
Exploring reactive programming with JavaExploring reactive programming with Java
Exploring reactive programming with Java
 
Java Control Statements
Java Control StatementsJava Control Statements
Java Control Statements
 
Go Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii ShapovalGo Is Your Next Language — Sergii Shapoval
Go Is Your Next Language — Sergii Shapoval
 
JS knowing-nuances
JS knowing-nuancesJS knowing-nuances
JS knowing-nuances
 
Loop control structure
Loop control structureLoop control structure
Loop control structure
 
Best practices for unit testing RxJava
Best practices for unit testing RxJavaBest practices for unit testing RxJava
Best practices for unit testing RxJava
 
Practical introduction to the actor model
Practical introduction to the actor modelPractical introduction to the actor model
Practical introduction to the actor model
 
For
ForFor
For
 
Reactive programming in Java
Reactive programming in JavaReactive programming in Java
Reactive programming in Java
 
Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016Ratpack JVM_MX Meetup February 2016
Ratpack JVM_MX Meetup February 2016
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
Groovy MOPping
Groovy MOPpingGroovy MOPping
Groovy MOPping
 
Dangers of parallel streams
Dangers of parallel streamsDangers of parallel streams
Dangers of parallel streams
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
 

Viewers also liked

JavaScript Tools and Implementation
JavaScript Tools and ImplementationJavaScript Tools and Implementation
JavaScript Tools and ImplementationCharles Russell
 
JavaScript Introductin to Functions
JavaScript Introductin to FunctionsJavaScript Introductin to Functions
JavaScript Introductin to FunctionsCharles Russell
 
JavaScript Comments and Conditionals
JavaScript Comments and ConditionalsJavaScript Comments and Conditionals
JavaScript Comments and ConditionalsCharles Russell
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String FunctionsAvanitrambadiya
 
Boom Boom! Revolution Press Kit
Boom Boom! Revolution Press KitBoom Boom! Revolution Press Kit
Boom Boom! Revolution Press KitBoom Boom! Cards
 
Designing Websites in Photoshop
Designing Websites in PhotoshopDesigning Websites in Photoshop
Designing Websites in PhotoshopBrunner
 
Creating simple web design in photoshop
Creating simple web design in photoshopCreating simple web design in photoshop
Creating simple web design in photoshoplillianabe
 
Javascript - Break statement, type conversion, regular expression
Javascript - Break statement, type conversion, regular expressionJavascript - Break statement, type conversion, regular expression
Javascript - Break statement, type conversion, regular expressionShivam gupta
 

Viewers also liked (15)

JavaScript Tools and Implementation
JavaScript Tools and ImplementationJavaScript Tools and Implementation
JavaScript Tools and Implementation
 
JavaScript Introductin to Functions
JavaScript Introductin to FunctionsJavaScript Introductin to Functions
JavaScript Introductin to Functions
 
JavaScript Comments and Conditionals
JavaScript Comments and ConditionalsJavaScript Comments and Conditionals
JavaScript Comments and Conditionals
 
Javascript built in String Functions
Javascript built in String FunctionsJavascript built in String Functions
Javascript built in String Functions
 
Boom Boom! Revolution Press Kit
Boom Boom! Revolution Press KitBoom Boom! Revolution Press Kit
Boom Boom! Revolution Press Kit
 
Designing Websites in Photoshop
Designing Websites in PhotoshopDesigning Websites in Photoshop
Designing Websites in Photoshop
 
XML
XMLXML
XML
 
Open Source Software
Open Source SoftwareOpen Source Software
Open Source Software
 
Js objects
Js objectsJs objects
Js objects
 
JavaScript Operators
JavaScript OperatorsJavaScript Operators
JavaScript Operators
 
Creating simple web design in photoshop
Creating simple web design in photoshopCreating simple web design in photoshop
Creating simple web design in photoshop
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
 
JavaScript Variables
JavaScript VariablesJavaScript Variables
JavaScript Variables
 
Javascript - Break statement, type conversion, regular expression
Javascript - Break statement, type conversion, regular expressionJavascript - Break statement, type conversion, regular expression
Javascript - Break statement, type conversion, regular expression
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 

Similar to JavaScript iteration (20)

Programming in python - Week 4
Programming in python  - Week 4Programming in python  - Week 4
Programming in python - Week 4
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
 
dizital pods session 5-loops.pptx
dizital pods session 5-loops.pptxdizital pods session 5-loops.pptx
dizital pods session 5-loops.pptx
 
C language 2
C language 2C language 2
C language 2
 
Loop structures
Loop structuresLoop structures
Loop structures
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Phasers to stunning
Phasers to stunningPhasers to stunning
Phasers to stunning
 
Multithreading programming in java
Multithreading programming in javaMultithreading programming in java
Multithreading programming in java
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
1660213363910.pdf
1660213363910.pdf1660213363910.pdf
1660213363910.pdf
 
Chapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdfChapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdf
 
Loops in C.pptx
Loops in C.pptxLoops in C.pptx
Loops in C.pptx
 
Using loops
Using loopsUsing loops
Using loops
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14
 
R loops
R   loopsR   loops
R loops
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
 

Recently uploaded

Development Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appsDevelopment Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appscristianmanaila2
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan
 
Premier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfPremier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfappinfoedgeca
 
Statistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfStatistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfOndejSur
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsrahman018755
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkklolsDocherty
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyDamar Juniarto
 
Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxChloeMeadows1
 
I’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 ShirtI’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 Shirtrahman018755
 
Free scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirtsFree scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirtsrahman018755
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideVarun Mithran
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebJie Liau
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsrahman018755
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?Linksys Velop Login
 
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.Tortogel
 
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresenceCyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresencePC Doctors NET
 

Recently uploaded (17)

Development Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of appsDevelopment Lifecycle.pptx for the secure development of apps
Development Lifecycle.pptx for the secure development of apps
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
Premier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdfPremier Mobile App Development Agency in USA.pdf
Premier Mobile App Development Agency in USA.pdf
 
Statistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdfStatistical Analysis of DNS Latencies.pdf
Statistical Analysis of DNS Latencies.pdf
 
Reggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirtsReggie miller choke t shirts
Reggie miller choke t shirtsReggie miller choke t shirts
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
Production 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptxProduction 2024 sunderland culture final - Copy.pptx
Production 2024 sunderland culture final - Copy.pptx
 
I’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 ShirtI’ll See Y’All Motherfuckers In Game 7 Shirt
I’ll See Y’All Motherfuckers In Game 7 Shirt
 
Free scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirtsFree scottie t shirts Free scottie t shirts
Free scottie t shirts Free scottie t shirts
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWebiThome_CYBERSEC2024_Drive_Into_the_DarkWeb
iThome_CYBERSEC2024_Drive_Into_the_DarkWeb
 
Thank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirtsThank You Luv I’ll Never Walk Alone Again T shirts
Thank You Luv I’ll Never Walk Alone Again T shirts
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
TORTOGEL TELAH MENJADI SALAH SATU PLATFORM PERMAINAN PALING FAVORIT.
 
GOOGLE Io 2024 At takes center stage.pdf
GOOGLE Io 2024 At takes center stage.pdfGOOGLE Io 2024 At takes center stage.pdf
GOOGLE Io 2024 At takes center stage.pdf
 
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital PresenceCyber Security Services Unveiled: Strategies to Secure Your Digital Presence
Cyber Security Services Unveiled: Strategies to Secure Your Digital Presence
 

JavaScript iteration

  • 2. Changes in Direction ● In the previous video we allowed our program to change flow to one of many different program blocks ● But that is not the only direction change we may want. It is often desireable to repeatedly execute the same block ● Looking for some value in a list ● Sending a group email ● In other words we want to loop
  • 3. The While loop ● At the top of the loop the condition is checked ● If the condition is met then execute code block ● Loop will continue until condition not met. while (conditional expression) { //Do some stuff } ● Be sure that eventually the condition will not be met otherwise you get an infinite loop;
  • 4. The Do loop ● At the bottom of the loop condition is checked ● Assures the code block will be executed at least once ● Loop continues until condition false do { //code to execute goes here } while (conditional expression);
  • 5. Basic For loop ● Executes the loop a number of times ● Has three statements ● First excutes before the loop is executed – Usually used for initialization ● Second conditional expression – Code executes if true ● Third – Executes after the code block before the next iteration
  • 6. Basic For Syntax for (init ; conditional exp; prepForNext) { //do some stuff }
  • 7. For looping through properties ● Used to examine properties of an object ● Important to filter as all properties examined even those inherited from parent and its parent.... for (variable in Object) { if ( Object.hasOwnProperty(variable) { //code to execute } }
  • 8. Cutting the loop ● break ● Halts code execution in the loop – Stop further execution of code block and exit the loop ● continue ● Halts execution of the rest of the code block ● Continues next iteration
  • 9. Summary ● Iteration is another word for looping ● While loops check for conditional at the top of the loop ● Be wary of the infinite loop ● Do loops check conditional at bottom of the loop ● Basic for loops allow loops to be controlled by number of executions ● For in loops will check properties of Objects and Arrays ● Be sure to use hasOwnProperty method.