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

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing javascript.info — Output even numbers in the loop

  • Tutorial
  • The JavaScript language
  • JavaScript Fundamentals
  • Loops: while and for
back to the lesson

Output even numbers in the loop

importance: 5

Use the for loop to output even numbers from 2 to 10.

Run the demo

for (let i = 2; i <= 10; i++) {
  if (i % 2 == 0) {
    alert( i );
  }
}

We use the “modulo” operator % to get the remainder and check for the evenness here.

You are visitor 01402503 — 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.