SlideShare a Scribd company logo
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 (20)

PPTX
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
PPTX
While , For , Do-While Loop
Abhishek Choksi
 
PDF
JAVA Threads explained
Pradhan Rishi Sharma
 
PPTX
A tale of two(many) proxies
Mohan Dutt
 
PPTX
Modern Programming Languages - An overview
Ayman Mahfouz
 
PDF
Exploring reactive programming with Java
Miro Cupak
 
PPTX
Java Control Statements
KadarkaraiSelvam
 
PPTX
Go Is Your Next Language — Sergii Shapoval
GlobalLogic Ukraine
 
PPTX
JS knowing-nuances
Ramesh Ramalingam
 
PPTX
Loop control structure
narmadhakin
 
PDF
Best practices for unit testing RxJava
Simon Percic
 
KEY
Practical introduction to the actor model
Georgios Gousios
 
PPTX
For
sidneyodingo
 
PDF
Reactive programming in Java
Miro Cupak
 
PDF
Ratpack JVM_MX Meetup February 2016
Domingo Suarez Torres
 
PDF
Java Repetiotion Statements
Huda Alameen
 
PDF
Groovy MOPping
Izzet Mustafaiev
 
PDF
Dangers of parallel streams
Lukáš Křečan
 
PPTX
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
PDF
War of Native Speed on Web (SITCON2016)
Min-Yih Hsu
 
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
While , For , Do-While Loop
Abhishek Choksi
 
JAVA Threads explained
Pradhan Rishi Sharma
 
A tale of two(many) proxies
Mohan Dutt
 
Modern Programming Languages - An overview
Ayman Mahfouz
 
Exploring reactive programming with Java
Miro Cupak
 
Java Control Statements
KadarkaraiSelvam
 
Go Is Your Next Language — Sergii Shapoval
GlobalLogic Ukraine
 
JS knowing-nuances
Ramesh Ramalingam
 
Loop control structure
narmadhakin
 
Best practices for unit testing RxJava
Simon Percic
 
Practical introduction to the actor model
Georgios Gousios
 
Reactive programming in Java
Miro Cupak
 
Ratpack JVM_MX Meetup February 2016
Domingo Suarez Torres
 
Java Repetiotion Statements
Huda Alameen
 
Groovy MOPping
Izzet Mustafaiev
 
Dangers of parallel streams
Lukáš Křečan
 
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
War of Native Speed on Web (SITCON2016)
Min-Yih Hsu
 

Viewers also liked (15)

PPT
JavaScript Tools and Implementation
Charles Russell
 
PPT
JavaScript Introductin to Functions
Charles Russell
 
PPT
JavaScript Comments and Conditionals
Charles Russell
 
PPT
Javascript built in String Functions
Avanitrambadiya
 
PDF
Boom Boom! Revolution Press Kit
Boom Boom! Cards
 
PDF
Designing Websites in Photoshop
Brunner
 
PPT
Open Source Software
Charles Russell
 
PPT
Js objects
Charles Russell
 
PPT
JavaScript Operators
Charles Russell
 
PPTX
Creating simple web design in photoshop
lillianabe
 
PPT
JavaScript Data Types
Charles Russell
 
PPT
JavaScript Variables
Charles Russell
 
PPTX
Javascript - Break statement, type conversion, regular expression
Shivam gupta
 
PPT
JavaScript Introduction
Charles Russell
 
JavaScript Tools and Implementation
Charles Russell
 
JavaScript Introductin to Functions
Charles Russell
 
JavaScript Comments and Conditionals
Charles Russell
 
Javascript built in String Functions
Avanitrambadiya
 
Boom Boom! Revolution Press Kit
Boom Boom! Cards
 
Designing Websites in Photoshop
Brunner
 
Open Source Software
Charles Russell
 
Js objects
Charles Russell
 
JavaScript Operators
Charles Russell
 
Creating simple web design in photoshop
lillianabe
 
JavaScript Data Types
Charles Russell
 
JavaScript Variables
Charles Russell
 
Javascript - Break statement, type conversion, regular expression
Shivam gupta
 
JavaScript Introduction
Charles Russell
 
Ad

Similar to JavaScript iteration (20)

PPTX
JS Control Statements and Functions.pptx
Ramakrishna Reddy Bijjam
 
DOCX
Loops and iteration.docx
NkurikiyimanaGodefre
 
PDF
1660213363910.pdf
CuentaTemporal4
 
PPTX
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
PDF
JavaScript Looping Statements
Janssen Harvey Insigne
 
PPTX
While loop and for loop 06 (js)
AbhishekMondal42
 
PPTX
Loops in java script
Ravi Bhadauria
 
PPTX
JavaScript Session 3
Muhammad Ehtisham Siddiqui
 
PPTX
10. session 10 loops and arrays
Phúc Đỗ
 
PDF
Intro to JavaScript - Week 3: Control Statements
Jeongbae Oh
 
PPTX
For And While Loop
Shuvo Malakar
 
PPTX
JavaScript Conditional Statements
Marlon Jamera
 
DOC
Web programming[10]
Muhammad Awaluddin
 
PPT
Javascript
Mallikarjuna G D
 
DOCX
Janakiram web
MARELLA CHINABABU
 
PPTX
control_javascript_for _beginners_and _pro.pptx
vivekkn69
 
PPT
Les origines de Javascript
Bernard Loire
 
PPT
The JavaScript Programming Language
Raghavan Mohan
 
PPT
The Java Script Programming Language
zone
 
PPT
Javascript
guest03a6e6
 
JS Control Statements and Functions.pptx
Ramakrishna Reddy Bijjam
 
Loops and iteration.docx
NkurikiyimanaGodefre
 
1660213363910.pdf
CuentaTemporal4
 
Cordova training : Day 3 - Introduction to Javascript
Binu Paul
 
JavaScript Looping Statements
Janssen Harvey Insigne
 
While loop and for loop 06 (js)
AbhishekMondal42
 
Loops in java script
Ravi Bhadauria
 
JavaScript Session 3
Muhammad Ehtisham Siddiqui
 
10. session 10 loops and arrays
Phúc Đỗ
 
Intro to JavaScript - Week 3: Control Statements
Jeongbae Oh
 
For And While Loop
Shuvo Malakar
 
JavaScript Conditional Statements
Marlon Jamera
 
Web programming[10]
Muhammad Awaluddin
 
Javascript
Mallikarjuna G D
 
Janakiram web
MARELLA CHINABABU
 
control_javascript_for _beginners_and _pro.pptx
vivekkn69
 
Les origines de Javascript
Bernard Loire
 
The JavaScript Programming Language
Raghavan Mohan
 
The Java Script Programming Language
zone
 
Javascript
guest03a6e6
 
Ad

Recently uploaded (20)

PPTX
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
PDF
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PPTX
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
PPTX
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
PPTX
internet básico presentacion es una red global
70965857
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PDF
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PPT
introductio to computers by arthur janry
RamananMuthukrishnan
 
PPTX
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
PDF
The Internet - By the numbers, presented at npNOG 11
APNIC
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
一比一原版(SUNY-Albany毕业证)纽约州立大学奥尔巴尼分校毕业证如何办理
Taqyea
 
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
Optimization_Techniques_ML_Presentation.pptx
farispalayi
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
L1A Season 1 ENGLISH made by A hegy fixed
toszolder91
 
PE introd.pptxfrgfgfdgfdgfgrtretrt44t444
nepmithibai2024
 
原版西班牙莱昂大学毕业证(León毕业证书)如何办理
Taqyea
 
internet básico presentacion es una red global
70965857
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
introductio to computers by arthur janry
RamananMuthukrishnan
 
PM200.pptxghjgfhjghjghjghjghjghjghjghjghjghj
breadpaan921
 
The Internet - By the numbers, presented at npNOG 11
APNIC
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 

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.