SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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
 
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
 
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
 

Último

Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxeditsforyah
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationMarko4394
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 

Último (17)

Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptx
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentation
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 

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.