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

  • SEARCH
  • Home
  • 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 7983565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:59:49+00:00 2026-06-04T10:59:49+00:00

Despite all known blogs about this issue i always doubt some results and my

  • 0

Despite all known blogs about this issue i always doubt some results and my personal tests shows that the well-said standard isn’t the best.

Declaring variables inside the loop, to keep them close to its scope and make it faster to be reached by the method but allocating more memory or declaring outside the for scope to save memory allocation but increase processing to iterate in a distant instance.

My results shows that method B is faster(sometimes), i want to know the background around this.

results vary and im not a bit-brusher guru.

So what you guys think about it?

Method A

var object:Object = new Object();
var loop:int = 100000
for (var i:int = 0; i < loop; i++)
{
    object = new Object();
    object.foo = foo;
    object.bar = bar;
}

OR

Method B

var loop:int = 100000
for (var i:int = 0; i < loop; i++)
{
    var object:Object = new Object()
    object.foo = foo;
    object.bar = bar;
}
  • 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-06-04T10:59:50+00:00Added an answer on June 4, 2026 at 10:59 am

    tldr; they are semantically equivalent and perform identically.

    There is only one variable called object in both cases presented. ActionScript, like JavaScript, “hoists” declarations. That is, var is really just a function-scoped annotation. This differs from C and Java where a new scope (and thus new variable) would have been created in the 2nd case.

    There is no difference in AS, however. The engine effectively treats the 2nd code identical to the first. (That being said, I prefer to “keep the var close” to where it is used, while understanding it is not relevant to the scope and has no bearing on performance.)

    See Action Script 3.0: Variables and, the Scope section in particular:

    The scope of a variable is the area of your code where the variable can be accessed by a lexical reference… In ActionScript 3.0, variables are always assigned the scope of the function or class in which they are declared.

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I lack understanding of some basic MVC concepts, despite all my searching. I created
I'm doing some research on the Groovy programming language, and despite all the information
Despite working on EE for about 3 weeks now, believe it or not, this
Newbie question about JavaFX that I haven't been able to answer, despite knowing it
Despite all the advances in 3D graphic engines, it strikes me as odd that
First of all, let me quickly explain why I brought this up despite similar
Very occasionally, despite all testing efforts, I get hit with a bug report from
This is a problem i wasn't able to solve despite extensive searches on the
**Despite how long this looks, I know it is very simple, I just added
I've made sure that all the files are in the root of the repository

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.