The document discusses JavaScript loops including for loops, while loops, and do-while loops. It provides examples of using each loop type to iterate through numbers or HTML elements. Break and continue statements are also covered, allowing the loop execution to be interrupted or skipped to the next iteration under certain conditions. Key loop concepts like initialization, condition checking, and incrementing are demonstrated in the examples.
An introduction to JavaScript that includes side-by-side comparisons with Python -- for journalism students. Based on the free JavaScript exercises/lessons at Codecademy: http://www.codecademy.com/tracks/javascript (Students in this course spent 4 weeks learning Python before they were introduced to JavaScript.)
We are covering following topics:
If...Else...Elseif Statements: if statement executes some code if one condition is true.
Switch Statement: Switch Statement tests a variable against a series of values.
For Loop: For loop executes a block of code a specified number of times.
While Loop: While loop executes a block of code as long as the specified condition is true.
Do…While Loop: Do...While loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.
This is an interactive PowerPoint presentation I made for my seminar at my workplace. It talks and illustrates how the JavaScript engine works when executing code. It also contains a step-by-step animation which demonstrates the usage of the JavaScript event loop.
Feel free to use and refer content. Copyrights reserved.
JavaScript, like it or not, has become the most important language on the web. Nearly every developer who builds Internet apps has to use it. But JavaScript can be tough to write and even tougher to read. So here are ten tips to help you get groovy with JavaScript.
Importance of loops in any programming language is immense, they allow us to reduce the number of lines in a code, making our code more readable and efficient.
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Nested Loops and Jumping Statements(Loop Control Statements), Goto statement in C, Return Statement in C Exit statement in C, For Loops with Nested Loops, While Loop with Nested Loop, Do-While Loop with Nested Loops, Break Statement, Continue Statement : visit us at : www.rozyph.com
The original Creative JavaScript tutorial, covering loops in JavaScript. This tutorial is aimed at creative people with no programming experience who are interested to learn loops JavaScript.
An introduction to JavaScript that includes side-by-side comparisons with Python -- for journalism students. Based on the free JavaScript exercises/lessons at Codecademy: http://www.codecademy.com/tracks/javascript (Students in this course spent 4 weeks learning Python before they were introduced to JavaScript.)
We are covering following topics:
If...Else...Elseif Statements: if statement executes some code if one condition is true.
Switch Statement: Switch Statement tests a variable against a series of values.
For Loop: For loop executes a block of code a specified number of times.
While Loop: While loop executes a block of code as long as the specified condition is true.
Do…While Loop: Do...While loop will always execute the block of code once, it will then check the condition, and repeat the loop while the specified condition is true.
This is an interactive PowerPoint presentation I made for my seminar at my workplace. It talks and illustrates how the JavaScript engine works when executing code. It also contains a step-by-step animation which demonstrates the usage of the JavaScript event loop.
Feel free to use and refer content. Copyrights reserved.
JavaScript, like it or not, has become the most important language on the web. Nearly every developer who builds Internet apps has to use it. But JavaScript can be tough to write and even tougher to read. So here are ten tips to help you get groovy with JavaScript.
Importance of loops in any programming language is immense, they allow us to reduce the number of lines in a code, making our code more readable and efficient.
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Nested Loops and Jumping Statements(Loop Control Statements), Goto statement in C, Return Statement in C Exit statement in C, For Loops with Nested Loops, While Loop with Nested Loop, Do-While Loop with Nested Loops, Break Statement, Continue Statement : visit us at : www.rozyph.com
The original Creative JavaScript tutorial, covering loops in JavaScript. This tutorial is aimed at creative people with no programming experience who are interested to learn loops JavaScript.
JavaScript is a versatile programming language primarily used for building dynamic and interactive web applications. Developed by Netscape Communications Corporation in the mid-1990s, JavaScript has since become one of the most popular programming languages worldwide. Here's a detailed description of JavaScript:
Introduction to JavaScript:
JavaScript is a high-level, interpreted programming language that allows developers to add functionality, interactivity, and behavior to web pages. Unlike server-side languages like PHP or Python, JavaScript is executed on the client-side, meaning it runs within the user's web browser. This enables dynamic manipulation of webpage content without requiring communication with the server.
This 7-second Brain Wave Ritual Attracts Money To You.!nirahealhty
Discover the power of a simple 7-second brain wave ritual that can attract wealth and abundance into your life. By tapping into specific brain frequencies, this technique helps you manifest financial success effortlessly. Ready to transform your financial future? Try this powerful ritual and start attracting money today!
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesSanjeev Rampal
Talk presented at Kubernetes Community Day, New York, May 2024.
Technical summary of Multi-Cluster Kubernetes Networking architectures with focus on 4 key topics.
1) Key patterns for Multi-cluster architectures
2) Architectural comparison of several OSS/ CNCF projects to address these patterns
3) Evolution trends for the APIs of these projects
4) Some design recommendations & guidelines for adopting/ deploying these solutions.
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC
Ellisha Heppner, Grant Management Lead, presented an update on APNIC Foundation to the PNG DNS Forum held from 6 to 10 May, 2024 in Port Moresby, Papua New Guinea.
1.Wireless Communication System_Wireless communication is a broad term that i...JeyaPerumal1
Wireless communication involves the transmission of information over a distance without the help of wires, cables or any other forms of electrical conductors.
Wireless communication is a broad term that incorporates all procedures and forms of connecting and communicating between two or more devices using a wireless signal through wireless communication technologies and devices.
Features of Wireless Communication
The evolution of wireless technology has brought many advancements with its effective features.
The transmitted distance can be anywhere between a few meters (for example, a television's remote control) and thousands of kilometers (for example, radio communication).
Wireless communication can be used for cellular telephony, wireless access to the internet, wireless home networking, and so on.
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBrad Spiegel Macon GA
Brad Spiegel Macon GA’s journey exemplifies the profound impact that one individual can have on their community. Through his unwavering dedication to digital inclusion, he’s not only bridging the gap in Macon but also setting an example for others to follow.
1. MATERI PERKULIAHAN HTML DAN JAVASCRIPT
Pertemuan Minggu 11
Oleh: Mohamad Saefudin, Skom, MMSI
(For Loop, While Loop )
JavaScript For Loop
Loops in JavaScript are used to execute the same block of code a specified
number of times or while a specified condition is true.
Examples
For loop
How to write a for loop. Use a For loop to run the same block of code a specified
number of times.
Looping through HTML headers
How to use the for loop to loop through the different HTML headers.
JavaScript Loops
Very often when you write code, you want the same block of code to run over
and over again in a row. Instead of adding several almost equal lines in a script
we can use loops to perform a task like this.
In JavaScript there are two different kind of loops:
• for - loops through a block of code a specified number of times
• while - loops through a block of code while a specified condition is true
The for Loop
The for loop is used when you know in advance how many times the script
should run.
Syntax
for (var=startvalue;var<=endvalue;var=var+increment)
{
code to be executed
}
2. Example
Explanation: The example below defines a loop that starts with i=0. The loop will
continue to run as long as i is less than, or equal to 10. i will increase by 1 each
time the loop runs.
Note: The increment parameter could also be negative, and the <= could be any
comparing statement.
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=5;i++)
{
document.write("The number is " + i)
document.write("<br />")
}
</script>
</body>
</html>
Result
The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
Example:
<html>
<body>
<script type="text/javascript">
for (i = 0; i <= 5; i++)
{
document.write("The number is " + i)
document.write("<br />")
}
</script>
<p>Explanation:</p>
<p>This for loop starts with i=0.</p>
<p>As long as <b>i</b> is less than, or equal to 5, the loop will continue to run.</p>
<p><b>i</b> will increase by 1 each time the loop runs.</p>
</body>
</html>
3. Result:
The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
Explanation:
This for loop starts with i=0.
As long as i is less than, or equal to 5, the loop will continue to run.
i will increase by 1 each time the loop runs.
Eamples (Looping through HTML headers) :
<html>
<body>
<script type="text/javascript">
for (i = 1; i <= 6; i++)
{
document.write("<h" + i + ">This is header " + i)
document.write("</h" + i + ">")
}
</script>
</body>
</html>
Result:
This is header 1
This is header 2
This is header 3
This is header 4
This is header 5
This is header 6
4. JavaScript While Loop
Loops in JavaScript are used to execute the same block of code a specified
number of times or while a specified condition is true.
1. While loop
How to write a while loop. Use a while loop to run the same block of code
while a specified condition is true.
2. Do while loop
How to write a do...while loop. Use a do...while loop to run the same block of
code while a specified condition is true. This loop will always be executed at
least once, even if the condition is false, because the statements are
executed before the condition is tested.
While loop
The while loop is used when you want the loop to execute and continue
executing while the specified condition is true.
while (var<=endvalue)
{
code to be executed
}
Catatan: Tanda <= digunakan untuk membandingkan statement.
Contoh 01:
Penjelasan: Contoh di bawah ini menjelaskan pengulangan di mulai dengan I =0,
dan pengulangan akan bertambah sampai I bernilai kurang atau sama dengan 5
dengan penambahan 1 nilai setiap pengulangan.
<html>
<body>
<script type="text/javascript">
var i=0
while (i<=5)
{
document.write("Angka ke " + i)
document.write("<br />")
i=i+1
}
</script>
</body></html>
5. Hasil 01:
Angka ke 0
Angka ke 1
Angka ke 2
Angka ke 3
Angka ke 4
Angka ke 5
Contoh 02:
<html>
<body>
<script type="text/javascript">
i = 0
while (i <= 5)
{
document.write("Angka Ke: " + i)
document.write("<br />")
i++
}
</script>
<p>Penjelasan:</p>
<p><b>i</b> Mempunyai nilai awal 0.</p>
<p>While <b>i</b> sampai bernilai, atau sama dengan, 5,
pengulangan akan berjalan.</p>
<p><b>i</b> akan bertambah niali 1 setiap pengulangan.</p>
</body>
</html>
Hasil 02:
Angka Ke: 0
Angka Ke: 1
Angka Ke: 2
Angka Ke: 3
Angka Ke: 4
Angka Ke: 5
Explanation:
i Mempunyai nilai awal 0.
While i sampai bernilai, atau sama dengan, 5, pengulangan akan berjalan.
i akan bertambah nilai 1 setiap pengulangan.
6. do...while Loop
The do...while loop is a variant of the while loop. This loop will always execute a
block of code ONCE, and then it will repeat the loop as long as the specified
condition is true. This loop will always be executed at least once, even if the
condition is false, because the code is executed before the condition is tested.
do
{
code to be executed
}
while (var<=endvalue)
Example
<html>
<body>
<script type="text/javascript">
var i=0
do
{
document.write("The number is " + i)
document.write("<br />")
i=i+1
}
while (i<0)
</script>
</body>
</html>
Result
The number is 0
JavaScript Break and Continue
There are two special statements that can be used inside loops: break and
continue.
1. Break statement
Use the break statement to break the loop.
7. 2. Continue statement
Use the continue statement to break the current loop and continue with the next
value.
There are two special statements that can be used inside loops: break and continue.
Break
The break command will break the loop and continue executing the code that
follows after the loop (if any).
Example
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3){break}
document.write("The number is " + i)
document.write("<br />")
}
</script>
<p>Explanation: The loop will break when i=3.</p>
</body>
</html>
Result
The number is 0
The number is 1
The number is 2
Explanation: The loop will break when i=3.
Continue
The continue command will break the current loop and continue with the next
value.
Example
<html>
<body>
<script type="text/javascript">
var i=0
for (i=0;i<=10;i++)
{
if (i==3){continue}
document.write("The number is " + i)
document.write("<br />")
}
8. </script>
<p>Explanation: The loop will break the current loop and continue with
the next value when i=3.</p>
</body>
</html>
Result
The number is 0
The number is 1
The number is 2
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10
Explanation: The loop will break the current loop and continue with the next value when
i=3.