dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] found some serious problem in for in loop

  1. #1
    Senior Member inder_s2010's Avatar
    Join Date
    Apr 2004
    Location
    don't no
    Posts
    198

    [F8] found some serious problem in for in loop

    hi guys,

    today i faced a amazing problem in for(var i in Object) loop.
    I declared an array and reversed it, then tried to trace it with for in loop.
    here's a example try it...

    Code:
    var nums:Array = new Array(1,2,3,4)
    nums.reverse()
    trace(nums);
    for(var i in nums)
    {
    	trace(i+" -- "+nums[i]);
    }
    inder

  2. #2
    Senior Member inder_s2010's Avatar
    Join Date
    Apr 2004
    Location
    don't no
    Posts
    198
    anyone facing the same? any thoughts..? suggestions?
    inder

  3. #3
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    It would be helpful to give the output and what you're trying to do, you're making people who respond to you do a lot of work and guessing.

    I'm guessing that you were surprised they didn't trace out in order. I agree it's weird and don't know why it works that way. Assuming you need to get them in order, it's as easy as doing a for loop like:

    Code:
    for (i=0; i<nums.length; i++){
       trace(i+" -- "+nums[i]);
    }
    
    or
    
    for (i=nums.length; i>0; i--){
       trace(i+" -- "+nums[i]);
    }

  4. #4
    Senior Member inder_s2010's Avatar
    Join Date
    Apr 2004
    Location
    don't no
    Posts
    198
    i just faced a problem in my practice. and i wanted to share that problem with everyone. that's it... nothing complicated and guessing work.
    inder

  5. #5
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    So you had a problem, but none of your posts say what the problem was...did I guess it right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center