Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7552689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:50:42+00:00 2026-05-30T10:50:42+00:00

I cam across the following function in javascript: for (var number = 0; number

  • 0

I cam across the following function in javascript:

for (var number = 0; number <= 12; number = number + 2)
  show(number);

The Output is the following

0
2
4
6
8
10
12

I expected it to be

2
4
6
8
10
12
14

Why is the “0” shown first and not “2” since the “number = number + 2″comes before the “show(number);”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:50:44+00:00Added an answer on May 30, 2026 at 10:50 am

    This because the order of the loop is like this:

    1. Init number.
    2. Check the condition.
    3. Run the loop.
    4. Increase number by 2.

    and then 2-4 again until the condition is false, if so exits the loop.

    the for loop translate to something like this:

    var number = 0;
    while (number <= 12)
    {
      show(number);
      number = number + 2;
    }
    

    In general for loop always work like this:

    for(Init Variable; Condition ; Changing Variable)
    {
       //Some Code
    }
    

    translates to:

    Init Variable
    while (Condition )
    {
      //Some Code
    
      Changing Variable
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cam across a Java related question recently that was (to paraphrase): What reasons
The function getPageDimensions (of CAM::PDF) returns same values for both portrait and landscape pages.
I was working on my website when I cam across this problem, I have
I cam across this recently : here public int print(Graphics g, PageFormat pf, int
this is my flash as3 code : var cam:Camera; cam= Camera.getCamera(); var video:Video=new Video(200,200);
Is it possible to simulate a web-cam output so that other programs that use
Im making a flash app that will capture video from the users web-cam, show
Recently i cam across a statements : import static java.lang.System.out; import static java.lang.System.exit; I
i am not be able to detect/access my web cam using JMStudio when i
I connect a ıp cam(jpeg), and show this image, and ı repeat continually, After

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.