0% found this document useful (0 votes)
18 views

Chapter 9 - Loops

The document discusses different types of loops in JavaScript including for, while, do-while and for-in loops. It provides the syntax for each loop and describes what they are used for as well as how to exit loops using break and continue statements.

Uploaded by

marklipata2020
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)
18 views

Chapter 9 - Loops

The document discusses different types of loops in JavaScript including for, while, do-while and for-in loops. It provides the syntax for each loop and describes what they are used for as well as how to exit loops using break and continue statements.

Uploaded by

marklipata2020
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/ 3

CHAPTER 9 : LOOPS

OBJECTIVES:
➢ Learn what loops are
➢ Learn the different kinds of loops available in JavaScript
➢ Learn how to use loops

What is a Loop?

There are times when you want a block of code repeated over and over again until a certain condition is
satisfied. This can be done by creating a loop. A loop is a repetitive cycle of a block of code until the
condition is met.

In JavaScript, there are a variety of loops:

❖ For loop – it loops through a block of code within a specified number of times.
❖ While loop – it loops through a block of code until the condition is satisfied.
❖ Do-while loop – it is like while loop, however, it will execute the set of codes at least once
❖ For-in loop – it loops through the elements of an array.

If for instance, you want to exit from the loop after a condition has been met, you can use the break
statement. This statement will immediately break the loop and continue the execution of codes after the
said loop. The continue statement will break the current loop and will continue to the next value.

Syntax of a for loop for (var=startvalue;var<=endvalue;var=var+increment)

//Place your code here

}
Syntax of a while loop while (condition)

//Place your code here

Syntax of a do-while loop do

//Place your code here


} while (condition)

Video Links:

https://www.youtube.com/watch?v=24Wpg6njlYI
https://www.youtube.com/watch?v=DIA0J4vJBHQ

References:
https://www.w3schools.com/js/js_loop_for.asp
https://www.w3schools.com/js/js_loop_while.asp
https://www.w3schools.com/js/js_break.asp

You might also like