0% found this document useful (0 votes)
53 views16 pages

190 WDB Loops

The document discusses different types of loops used in JavaScript including for, while, for...of, and for...in loops. It provides examples of using loops to repeat code a certain number of times and iterate over arrays.

Uploaded by

Aiko Yukimura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views16 pages

190 WDB Loops

The document discusses different types of loops used in JavaScript including for, while, for...of, and for...in loops. It provides examples of using loops to repeat code a certain number of times and iterate over arrays.

Uploaded by

Aiko Yukimura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

The Web Developer Bootcamp

Js Loops
REPEAT STUFF. REPEAT STUFF. REPEAT STUFF.
LOOPS
Loops allow us to repeat code
"Print 'hello' 10 times
Sum all numbers in an array
There are multiple types:
for loop
while loop
for...of loop
for...in loop
For
Loops
Buckle Up!
For Loop Syntax
for (
[initialExpression];
[condition];
[incrementExpression]
)
Our First For Loop

start at 1 stop at 10 add 1 each time


Another Example

Start i at 50
Subtract 10 each
iteration
Keep going as
long as i >= 0
Infinite Loops
Looping Over Arrays

To loop over an array, start at index 0 and


continue looping to until last index (length-1)
NESTED LOOPS
While Loops

While loops continue running as


long as the test condition is true.
A Common Pattern
The Break Keyword
FOR...OF
A nice and easy way of
iterating over arrays
(or other iterable objects)

No Internet
Explorer Support
For...Of

for (variable of iterable) {


statement
}
An Example
Nested For...Of

You might also like