GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — javascript/loops/for.md at master · zeeshan-github-project/javascript

Expand file tree

/

for.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
38 lines (30 loc) · 845 Bytes
/

for.md

Copy path

File metadata and controls

38 lines (30 loc) · 845 Bytes
Raw
Copy raw file
Download raw file
Edit and raw actions

For Loop

The easiest form of a loop is the for statement. This one has a syntax that is similar to an if statement, but with more options:

for (condition; end condition; change) {
    // do it, do it now
}

Lets for example see how to execute the same code ten-times using a for loop:

for (var i = 0; i < 10; i = i + 1) {
  // do this code ten-times
}

Note: i = i + 1 can be written i++.

{% exercise %} Using a for-loop, create a variable named message that equals the concatenation of integers (0, 1, 2, ...) from 0 to 99. {% initial %} var message = ""; {% solution %} var message = "";

for(var i = 0; i < 100; i++){ message = message + i; } {% validation %} var message2 = ""

for(var i = 0; i < 100; i++){ message2 = message2 + i; } assert(message === message2); {% endexercise %}

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.