Article

Introduction

https://cdn.jsdelivr.net/npm/[email protected]/dist/js.cookie.min.js
Copy to clipboard

The for loop is the most common loop used in JavaScript programming.

The for loop consists of 3 parts:

1. The initialization stage

2. the test stage

3. the iteration stage.

In the initialization stage, we set a counter variable with a numerical value to indicate where the loop should start from.

In the test stage, a condition for the counter is specified so that the loop knows when to stop.

In the iteration stage, a statement is written so that the loop knows by how much to decrease or increase the counter value at each step.

A developer may implement a loop that writes the numbers 1 to 10 on the web page like this: https://raw.githubusercontent.com/finsweet/jqueryCourse/main/loops/ex1.js?actionable=true In the above example, the counter variable is declared in the first line, then initialized like so counter = 0.

The test statement is counter

<script>
$(document).ready(function(){
  XT1
});
</script>
Copy to clipboard
Send to Live Demo

Live demo

<div id="minidivpage" class="example-live"><div id="resultdiv"></div></div>

<script>    
$(document).ready(function() {
  XT1
});
</script>
<script>
  
</script>
Copy to clipboard
Press the Run Demo button to execute the scripts above.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Your browser is too small

Resize your browser to be at least 769px wide.